Examples of DcObject


Examples of net.datacrow.core.objects.DcObject

     */
    public static DcObject getItem(int module, String ID, int[] fields) {
        DataFilter df = new DataFilter(module);
        df.addEntry(new DataFilterEntry(module, DcObject._ID, Operator.EQUAL_TO, ID));
        List<DcObject> items = get(df, fields);
        DcObject item = items != null && items.size() > 0 ? items.get(0) : null;
        if (item != null) item.markAsUnchanged();
        return item;
    }   
View Full Code Here

Examples of net.datacrow.core.objects.DcObject

                client.notifyStartedSubProcess(items.size());
               
               
                int counter = 1;
                for (DcObject item : items) {
                    DcObject other = DataManager.getObjectForString(item.getModule().getIndex(), item.toString());
                    // Check if the item exists and if so, update the item with the found values. Else just create a new item.
                    // This is to make sure the order in which XML files are processed (first software, then categories)
                    // is of no importance (!).
                    try {
                        if (other != null) {
                            client.notifyMessage(DcResources.getText("msgItemExistsMerged", other.toString()));
                            other.setLastInLine(counter == items.size());
                            other.merge(item);
                            other.setChanged(DcObject._SYS_CREATED, false);
                            other.setChanged(DcObject._SYS_MODIFIED, false);
                            other.setValidate(false);
                            other.saveUpdate(true, false);
                        } else {
                            client.notifyMessage(DcResources.getText("msgItemNoExistsCreated", item.toString()));
                            item.setLastInLine(counter == items.size());
                            item.setValidate(false);
                            item.saveNew(true);
View Full Code Here

Examples of net.datacrow.core.objects.DcObject

        return true;
    }   
   
    @Override
    public DcObject parse(String filename, int directoryUsage) {
        DcObject book = DcModules.get(DcModules._BOOK).getItem();
       
        try {
            book.setValue(Book._A_TITLE, getName(filename, directoryUsage));
            book.setValue(Book._SYS_FILENAME, filename);
           
            // check if the filename contains an ISBN
            String isbn = String.valueOf(StringUtils.getContainedNumber(filename));
            boolean isIsbn10 = ISBN.isISBN10(isbn);
            boolean isIsbn13 = ISBN.isISBN13(isbn);
           
            // this can be used later on by the online search
            if (isIsbn10 || isIsbn13) {
                String isbn10 = isIsbn10 ? isbn : ISBN.getISBN10(isbn);
                String isbn13 = isIsbn13 ? isbn : ISBN.getISBN13(isbn);
                book.setValue(Book._J_ISBN10, isbn10);
                book.setValue(Book._N_ISBN13, isbn13);
            }
           
            if (filename.toLowerCase().endsWith("pdf")) {
               
                File file = new File(filename);
                FileISBNExtractor fileISBNExtractor = new FileISBNExtractor();
                fileISBNExtractor.setSearchMinBytes(30000);
                fileISBNExtractor.getTextReaderFactory().setPreferredPdfExtractor(new PDFBoxTextExtractor());
                ISBNCandidates isbnCandidates = fileISBNExtractor.getIsbnCandidates(file);
                org.chabanois.isbn.extractor.ISBN extractedISBN = isbnCandidates.getHighestScoreISBN();
               
                if (extractedISBN != null ) {
                    String s = extractedISBN.getIsbn();
                    if (s != null && s.length() > 0)
                        book.setValue(Book._N_ISBN13, ISBN.isISBN10(s) ? ISBN.getISBN13(s) :
                                                      ISBN.isISBN13(s) ? s : null);
                }
               
               
                RandomAccessFile raf = null;
                PDFFile pdffile;
                try {
                   
                    raf = new RandomAccessFile(file, "r");
                    FileChannel channel = raf.getChannel();
                    ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
                    pdffile = new PDFFile(buf);
                    pdffile.stop(1);
   
                    try {
                        book.setValue(Book._T_NROFPAGES, Long.valueOf(pdffile.getNumPages()));
                        Iterator<String> it = pdffile.getMetadataKeys();
                        while (it.hasNext()) {
                            String key = it.next();
                            String value = pdffile.getStringMetadata(key);
                           
                            if (!Utilities.isEmpty(value)) {
                                if (key.equalsIgnoreCase("Author"))
                                    DataManager.createReference(book, Book._G_AUTHOR, value);
                                if (key.equalsIgnoreCase("Title") && !value.trim().equalsIgnoreCase("untitled"))
                                    book.setValue(Book._A_TITLE, value);
                            }
                        }
                    } catch (IOException ioe) {
                        getClient().addMessage(DcResources.getText("msgCouldNotReadInfoFrom", filename));
                    }
   
                    // draw the first page to an image
                    PDFPage page = pdffile.getPage(0);
                    if (page != null) {
                        Rectangle rect = new Rectangle(0,0, (int)page.getBBox().getWidth(), (int)page.getBBox().getHeight());
                        Image front = page.getImage(rect.width, rect.height, rect, null, true, true);
                        book.setValue(Book._K_PICTUREFRONT, new DcImageIcon(Utilities.getBytes(new DcImageIcon(front))));
                    }
                } finally {
                    if (raf != null)
                        raf.close();
                   
View Full Code Here

Examples of net.datacrow.core.objects.DcObject

      if (items == null || items.size() <= 1)
        return items;
     
      List<DcObject> result = new ArrayList<DcObject>();
      List<DcObject> references = new ArrayList<DcObject>();
        DcObject ref;
        for (DcObject reference : items) {
            if (reference.getModule().getType() == DcModule._TYPE_MAPPING_MODULE) {
                ref = ((DcMapping) reference).getReferencedObject();
                if (ref.getModule().getType() == DcModule._TYPE_ASSOCIATE_MODULE)
                  ((DcAssociate )ref).setName();
               
                if (ref != null) references.add(ref);
               
                mappings = true;
View Full Code Here

Examples of net.datacrow.core.objects.DcObject

        }
    }

    @Override
    public DcObject parse(String filename, int directoryUsage) {
        DcObject ma = DcModules.get(DcModules._MUSICALBUM).getItem();

        try {
            MusicFile musicFile = new MusicFile(filename);
           
            String artist = musicFile.getArtist();
            String album = musicFile.getAlbum();
           
            String s = null;
            switch (directoryUsage) {
            case _DONOTUSE:
                break;
            case _DIRISALBUM:
                s = getDirectoryName(filename, 0);
                album = s != null ? s : album;
                break;
            case _DIRISARTISTS:
                s = getDirectoryName(filename, 0);
                artist = s != null ? s : artist;
                break;
            case _DIRISARTIST_SUBDIRISALBUM:
                s = getDirectoryName(filename, 0);
                album = s != null ? s : artist;

                s = getDirectoryName(filename, 1);
                artist = s != null ? s : album;

                break;
            }

            if (!Utilities.isEmpty(album)) {
                album = Converter.databaseValueConverter(album);
                ma = getAlbum(album, albums);
            }
           
            if (ma == null) {
                ma = DcModules.get(DcModules._MUSICALBUM).getItem();
                ma.setValue(MusicAlbum._A_TITLE, album);
               
                if (musicFile.getImage() != null)
                    ma.setValue(MusicAlbum._J_PICTUREFRONT, musicFile.getImage());
               
                setImages(filename, ma, MusicAlbum._J_PICTUREFRONT,
                                        MusicAlbum._K_PICTUREBACK,
                                        MusicAlbum._L_PICTURECD);
               
                DataManager.createReference(ma, MusicAlbum._F_ARTISTS, artist);
            }
           
            DcObject genre = null;
            if (musicFile.getGenre() != null)
                genre = DataManager.createReference(ma, MusicAlbum._G_GENRES, musicFile.getGenre());

            DcObject mt = DcModules.get(DcModules._MUSICTRACK).getItem();
            mt.setValue(MusicTrack._SYS_FILENAME, filename);
            Hash.getInstance().calculateHash(mt);
           
            mt.setValue(MusicTrack._A_TITLE, getName(filename, directoryUsage));
           
            String year = musicFile.getYear();
           
            if (year != null)
                year = year.indexOf("-") > -1 ? year.substring(0, year.indexOf("-")) : year;
           
            int track = musicFile.getTrack();
            track = track == 0 ? ma.getChildren() != null ?  ma.getChildren().size() + 1 : : track;
           
            mt.setValue(MusicTrack._K_QUALITY, musicFile.getBitrate() <= 0 ? null : Long.valueOf(musicFile.getBitrate()));
            mt.setValue(MusicTrack._J_PLAYLENGTH, musicFile.getLength() <= 0 ? null : Long.valueOf(musicFile.getLength()));
            mt.setValue(MusicTrack._L_ENCODING, musicFile.getEncodingType());
            mt.setValue(MusicTrack._A_TITLE, musicFile.getTitle());
            mt.setValue(MusicTrack._C_YEAR, year);
            mt.setValue(MusicTrack._F_TRACKNUMBER, track <= 0 ? null : Long.valueOf(track));
           
            if (genre != null)
                DataManager.createReference(mt, MusicTrack._H_GENRES, genre);
           
            DataManager.createReference(mt, MusicTrack._G_ARTIST, artist);               
View Full Code Here

Examples of net.datacrow.core.objects.DcObject

        wod.setRowIdx(objects.getData().getRowIndex());
        wod.setID((String) data.get(data.size() - 1));
        wod.setName(wod.getDcObject().toString());
        wod.load();
       
        DcObject dco = wod.getDcObject();
        String filename = dco.getFilename();
        File file = new File(filename);
        HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();

        int read = 0;
        byte[] bytes = new byte[1024];
View Full Code Here

Examples of net.datacrow.core.objects.DcObject

        int moduleIdx = objects.getModule();
        return DataManager.getItem(moduleIdx, (String) data.get(data.size() - 1));
    }
   
    private void loadImages() {
        DcObject dco = getItem();

        FacesContext fc = FacesContext.getCurrentInstance();
        VariableResolver vr = fc.getApplication().getVariableResolver();
        DcWebImages images = (DcWebImages) vr.resolveVariable(fc, "images");
        images.clear();
       
        for (DcField field : dco.getFields()) {
            if (field.getFieldType() == ComponentFactory._PICTUREFIELD) {
                Picture picture = (Picture) dco.getValue(field.getIndex());
               
                if (picture == null) continue;
               
                picture.loadImage(false);
                if (picture.getValue(Picture._D_IMAGE) != null) {
View Full Code Here

Examples of net.datacrow.core.objects.DcObject

            return redirect();
       
        if (!isValid(wo))
            return current();
       
        DcObject dco = wo.isNew() ? DcModules.get(wo.getModule()).getItem() :
                       DataManager.getItem(wo.getModule(), wo.getID()).clone();
       
        for (DcWebField wf : wo.getFields()) {
            if (!wf.isMultiRelate())
                dco.setValue(wf.getIndex(), wf.getValue());
        }

        for (DcWebField wf : wo.getTechnicalFields()) {
            if (!wf.isMultiRelate())
                dco.setValue(wf.getIndex(), wf.getValue());
        }
       
        if (wo.isChild()) {
            FacesContext fc = FacesContext.getCurrentInstance();
            VariableResolver vr = fc.getApplication().getVariableResolver();
            DcWebObject wod = (DcWebObject) vr.resolveVariable(fc, "webObject");
            dco.setValue( dco.getParentReferenceFieldIndex(), wod.getID());
        }
       
        try {
         
          dco.setUpdateGUI(false);
         
            if (wo.isNew()) {
                dco.setIDs();
                dco.saveNew(false);
            } else {
                dco.saveUpdate(false);
            }
           
        } catch (ValidationException ve) {
            FacesContext fc = FacesContext.getCurrentInstance();
            fc.addMessage("saveError", new FacesMessage(ve.getMessage()));
            return current();
        }
       
        if (wo.isNew()) {
            wo.initialize(wo.getModule());
            wo.setRowIdx(0);
            wo.setID(dco.getID());
            wo.setName(dco.toString());
            wo.load();
           
            return afterCreate();
        } else {
            return afterUpdated();
View Full Code Here

Examples of net.datacrow.core.objects.DcObject

        Object o = value;
        if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTREFERENCE) {
            o = DataManager.getItem(field.getReferenceIdx(), String.valueOf(value));
        } else if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
            Collection<DcObject> references = new ArrayList<DcObject>();
            DcObject reference = DataManager.getItem(field.getReferenceIdx(), String.valueOf(value));
            references.add(reference);
            o = references;
        }
       
        entry.setValue(o);
View Full Code Here

Examples of net.datacrow.core.objects.DcObject

        Collection<DcWebField> all = new ArrayList<DcWebField>();
        all.addAll(fields);
        all.addAll(technicalFields);
        all.addAll(pictureFields);
       
        DcObject dco = getDcObject();
        for (DcWebField wf : all) {
            DcField field = dco.getField(wf.getIndex());
            Object value = dco.getValue(field.getIndex());
            if (value != null) {
                if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTREFERENCE) {
                    if (!(value instanceof String))
                        value = ((DcObject) value).getID();
                    else
                        value = null;
                } else if (field.getValueType() == DcRepository.ValueTypes._PICTURE) {
                    value = "/mediaimages/" + ((Picture) value).getScaledFilename();
                } else if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
                    value = dco.getDisplayString(field.getIndex());
                } else if (value instanceof Number) {
                    value = String.valueOf(value);
                }
            }
            wf.setValue(value);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.