/** * Upload a file from the web * * @return */ public String uploadFromLink() { try { externalUrl = URLDecoder.decode(externalUrl, "UTF-8"); URL url = new URL(externalUrl); title = findFileName(url); File tmp = createTmpFile(); try { StorageController externalController = new StorageController("external"); FileOutputStream fos = new FileOutputStream(tmp); externalController.read(url.toString(), fos, true); Item item = uploadFile(tmp); if (item != null) { UserController uc = new UserController(null); user = uc.retrieve(getUser().getEmail()); ItemController ic = new ItemController(user); ic.create(item, collection.getId()); } externalUrl = ""; } finally { FileUtils.deleteQuietly(tmp); } } catch (Exception e) { logger.error("Error uploading file from link: " + externalUrl, e); fFiles.add(e.getMessage() + ": " + title); } return ""; }
/** Create the {@link Item} for the files which have been uploaded */ private void createItemForFiles() { ItemController ic = new ItemController(user); try { ic.create(itemList, collection.getId()); itemList = new ArrayList<Item>(); } catch (Exception e) { logger.error("Error creating files for upload", e); } }
/** * True if the filename is already used by an {@link Item} in this {@link CollectionImeji} * * @param filename * @return */ private boolean filenameExistsInCollection(String filename) { Search s = new Search(SearchType.ITEM, null); return s.searchSimpleForQuery( SPARQLQueries.selectContainerItemByFilename( collection.getId(), FilenameUtils.getBaseName(filename)), null) .size() > 0; }
/** Load the collection */ public void loadCollection() { if (id != null) { collection = ObjectLoader.loadCollectionLazy( ObjectHelper.getURI(CollectionImeji.class, id), sessionBean.getUser()); if (collection != null && getCollection().getId() != null) { ItemController ic = new ItemController(sessionBean.getUser()); collectionSize = ic.countContainerSize(collection.getId()); } } else { BeanHelper.error(sessionBean.getLabel("error") + "No ID in URL"); } }
/** * Search for an item in the current collection with the same filename. The filename must be * unique! * * @param filename * @return */ private Item findItemByFileName(String filename) { Search s = new Search(SearchType.ITEM, null); List<String> sr = s.searchSimpleForQuery( SPARQLQueries.selectContainerItemByFilename( collection.getId(), FilenameUtils.getBaseName(filename)), null); if (sr.size() == 0) throw new RuntimeException( "No item found with the filename " + FilenameUtils.getBaseName(filename)); if (sr.size() > 1) throw new RuntimeException( "Filename " + FilenameUtils.getBaseName(filename) + " not unique (" + sr.size() + " found)."); return ObjectLoader.loadItem(URI.create(sr.get(0)), user); }
/** Check that at least one image is editable and if the profile is not empty */ @Override public boolean isImageEditable() { return super.isImageDeletable() && ObjectCachedLoader.loadProfile(collection.getProfile()).getStatements().size() > 0; }
public void setDiscardComment(String comment) { collection.setDiscardComment(comment); }
public String getDiscardComment() { return collection.getDiscardComment(); }