Search in sources :

Example 1 with CfAsset

use of io.clownfish.clownfish.dbentities.CfAsset in project Clownfish by rawdog71.

the class CfAssetDAOImpl method findByScrapped.

@Override
public List<CfAsset> findByScrapped(boolean scrapped) {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfAsset.findByScrapped");
    query.setParameter("scrapped", scrapped);
    List<CfAsset> cfassetlist = query.getResultList();
    return cfassetlist;
}
Also used : CfAsset(io.clownfish.clownfish.dbentities.CfAsset) TypedQuery(javax.persistence.TypedQuery) Session(org.hibernate.Session)

Example 2 with CfAsset

use of io.clownfish.clownfish.dbentities.CfAsset in project Clownfish by rawdog71.

the class CfAssetDAOImpl method findByPublicuse.

@Override
public List<CfAsset> findByPublicuse(boolean publicuse) {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfAsset.findByPublicuse");
    query.setParameter("publicuse", publicuse);
    List<CfAsset> cfassetlist = query.getResultList();
    return cfassetlist;
}
Also used : CfAsset(io.clownfish.clownfish.dbentities.CfAsset) TypedQuery(javax.persistence.TypedQuery) Session(org.hibernate.Session)

Example 3 with CfAsset

use of io.clownfish.clownfish.dbentities.CfAsset in project Clownfish by rawdog71.

the class CfAssetDAOImpl method findByName.

@Override
public CfAsset findByName(String name) {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfAsset.findByName");
    query.setParameter("name", name);
    CfAsset cfasset = (CfAsset) query.getSingleResult();
    return cfasset;
}
Also used : CfAsset(io.clownfish.clownfish.dbentities.CfAsset) TypedQuery(javax.persistence.TypedQuery) Session(org.hibernate.Session)

Example 4 with CfAsset

use of io.clownfish.clownfish.dbentities.CfAsset in project Clownfish by rawdog71.

the class AssetLibrary method onSelect.

/**
 * Selection of an asset list
 * Updates the selected assets in the asset list
 * @param event
 */
public void onSelect(SelectEvent event) {
    selectedAssetlist = (CfAssetlist) event.getObject();
    filteredAssetcontent = cfassetService.findAll();
    List<CfAssetlistcontent> selectedassetlist = cfassetlistcontentService.findByAssetlistref(selectedAssetlist.getId());
    selectedAssetcontent.clear();
    if (!selectedassetlist.isEmpty()) {
        for (CfAssetlistcontent assetcontent : selectedassetlist) {
            CfAsset selectedAasset = cfassetService.findById(assetcontent.getCfAssetlistcontentPK().getAssetref());
            selectedAssetcontent.add(selectedAasset);
        }
    }
}
Also used : CfAsset(io.clownfish.clownfish.dbentities.CfAsset) CfAssetlistcontent(io.clownfish.clownfish.dbentities.CfAssetlistcontent)

Example 5 with CfAsset

use of io.clownfish.clownfish.dbentities.CfAsset in project Clownfish by rawdog71.

the class AssetList method handleFileUpload.

/**
 * Handles the file upload
 * Stores the files in the media path
 * Tika parser retrieves the metadata
 * Lucene indexes the assets
 * @param event
 * @throws org.apache.tika.exception.TikaException
 * @throws org.xml.sax.SAXException
 */
public void handleFileUpload(FileUploadEvent event) throws TikaException, SAXException {
    String filename = event.getFile().getFileName().toLowerCase();
    LOGGER.info("UPLOAD: {}", filename);
    HashMap<String, String> metamap = new HashMap<>();
    try {
        File result = new File(folderUtil.getMedia_folder() + File.separator + filename);
        InputStream inputStream;
        try (FileOutputStream fileOutputStream = new FileOutputStream(result)) {
            byte[] buffer = new byte[64535];
            int bulk;
            inputStream = event.getFile().getInputStream();
            while (true) {
                bulk = inputStream.read(buffer);
                if (bulk < 0) {
                    break;
                }
                fileOutputStream.write(buffer, 0, bulk);
                fileOutputStream.flush();
            }
            fileOutputStream.close();
        }
        inputStream.close();
        // detecting the file type using detect method
        String fileextension = FilenameUtils.getExtension(folderUtil.getMedia_folder() + File.separator + filename);
        Parser parser = new AutoDetectParser();
        BodyContentHandler handler = new BodyContentHandler(-1);
        Metadata metadata = new Metadata();
        try (FileInputStream inputstream = new FileInputStream(result)) {
            ParseContext context = new ParseContext();
            parser.parse(inputstream, handler, metadata, context);
        // System.out.println(handler.toString());
        }
        // getting the list of all meta data elements
        String[] metadataNames = metadata.names();
        for (String name : metadataNames) {
            // System.out.println(name + ": " + metadata.get(name));
            metamap.put(name, metadata.get(name));
        }
        CfAsset newasset = new CfAsset();
        newasset.setName(filename);
        newasset.setFileextension(fileextension.toLowerCase());
        newasset.setMimetype(metamap.get("Content-Type"));
        newasset.setImagewidth(metamap.get("Image Width"));
        newasset.setImageheight(metamap.get("Image Height"));
        newasset.setPublicuse(publicusage);
        newasset.setUploadtime(new DateTime().toDate());
        cfassetService.create(newasset);
        assetlist = cfassetService.findAll();
        // Index the uploaded assets and merge the Index files
        if ((null != folderUtil.getIndex_folder()) && (!folderUtil.getMedia_folder().isEmpty())) {
            Thread assetindexer_thread = new Thread(assetIndexer);
            assetindexer_thread.start();
        }
        assetName = "";
        classcontentlist.initAssetlist();
        FacesMessage message = new FacesMessage("Succesful", filename + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, message);
    } catch (IOException | PersistenceException e) {
        LOGGER.error(e.getMessage());
        FacesMessage error = new FacesMessage("The files were not uploaded!");
        FacesContext.getCurrentInstance().addMessage(null, error);
    }
}
Also used : BodyContentHandler(org.apache.tika.sax.BodyContentHandler) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Metadata(org.apache.tika.metadata.Metadata) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DateTime(org.joda.time.DateTime) Parser(org.apache.tika.parser.Parser) AutoDetectParser(org.apache.tika.parser.AutoDetectParser) CfAsset(io.clownfish.clownfish.dbentities.CfAsset) FileOutputStream(java.io.FileOutputStream) ParseContext(org.apache.tika.parser.ParseContext) PersistenceException(javax.persistence.PersistenceException) AutoDetectParser(org.apache.tika.parser.AutoDetectParser) File(java.io.File) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

CfAsset (io.clownfish.clownfish.dbentities.CfAsset)29 IOException (java.io.IOException)14 CfAssetlist (io.clownfish.clownfish.dbentities.CfAssetlist)9 CfAssetlistcontent (io.clownfish.clownfish.dbentities.CfAssetlistcontent)9 ArrayList (java.util.ArrayList)8 Gson (com.google.gson.Gson)7 HashMap (java.util.HashMap)7 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 PrintWriter (java.io.PrintWriter)6 TypedQuery (javax.persistence.TypedQuery)6 Session (org.hibernate.Session)6 FileOutputStream (java.io.FileOutputStream)5 InputStream (java.io.InputStream)5 CfAssetkeyword (io.clownfish.clownfish.dbentities.CfAssetkeyword)4 CfAttributcontent (io.clownfish.clownfish.dbentities.CfAttributcontent)4 CfKeyword (io.clownfish.clownfish.dbentities.CfKeyword)4 CfAssetService (io.clownfish.clownfish.serviceinterface.CfAssetService)4 List (java.util.List)4 Logger (org.slf4j.Logger)4