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;
}
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;
}
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;
}
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);
}
}
}
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);
}
}
Aggregations