ContentFileBuilder location(String articleId, String fileName) { if(StringUtils.isNotEmpty(fileName)){ fileName = fileName.replaceAll("\\s+",CS.UNDERSCORE); } final String originalFilename = fileName; ArchiveObjectPath path = new ArchiveObjectPath(new YaddaObjectID(articleId), new String[]{FileTypes.FT_FULL_TEXT, originalFilename}); this.location = path.encode(); return this; }
public static boolean isValid(String uri) { try { ArchiveObjectPath.decode(uri); return true; } catch (URISyntaxException e) { return false; } catch (ServiceException e) { return false; } }
void encodeIfNotEncoded(ArchiveObjectPath aop){ String[] t=aop.getPath(); for (int i=0; i< t.length; i++){ t[i]=encodeIfNotEncoded(t[i]); } }
new ArchiveObject2Meta(SYSTEM_OBJECT_PATH.getRootId(), SYSTEM_OBJECT_TYPE, "nothing", null)); storageFacade.saveObject(SYSTEM_OBJECT_PATH.encode(), object, null, null); new ArchiveObject2Meta(new YaddaObjectID(new UUIDGenerator().generate(null)), ERROR_DUMPS_TYPE, "nothing", null)); storageFacade.saveObject(ERROR_DUMP_OBJECT_PATH.encode(), object, null, null); ArchiveObjectPath path = new ArchiveObjectPath(ERROR_DUMP_OBJECT_PATH, "dump_" + date); storageFacade.saveObject(path.encode(), object, null, null); return path.encode();
/** * Returns a path to the parent of the current object * * @return */ public ArchiveObjectPath getParent() { if (path.length > 0) { return new ArchiveObjectPath(rootId, (String[]) ArrayUtils .subarray(path, 0, path.length - 1)); } else return null; }
public String toString() { return encode(); }
@Override public Set<DocumentAttachment> process(String path, String parent, boolean downloadRemoteAttachments, File workingDirectory) throws InvalidAttachmentException { if (ArchiveObjectPath.isValid(path)) { return fetchYaddaContent(path, parent); } try { URL url = new URL(path); URI uri = new URI(url.getProtocol(), null, url.getHost(), url.getPort(), url.getPath(), url.getQuery(), null); String encodedPath = uri.toASCIIString(); Set<DocumentAttachment> attachments = new HashSet<DocumentAttachment>(); if (downloadRemoteAttachments) { try { DocumentAttachment documentAttachment = fetchRemoteContent(encodedPath, parent); attachments.add(documentAttachment); } catch (Exception e) { throw new InvalidAttachmentException(path, "Exception fetching remote attachment", e); } } return attachments; } catch (MalformedURLException | URISyntaxException e) { throw new InvalidAttachmentException(path, "Invalid attachment url"); } }
/** * Creates a path object from an URI * * @param uri * @return * @throws URISyntaxException * @throws ServiceException */ public static ArchiveObjectPath decode(String uri) throws URISyntaxException, ServiceException { URI decodedUri = new URI(uri).normalize(); if (!URI_SCHEME.equals(decodedUri.getScheme())) throw new ServiceException("Malformed object id " + uri); String[] pathParts = StringUtils.split(decodedUri.getPath(), "/"); String rootId = decodedUri.getAuthority(); YaddaObjectID id = null; if (StringUtils.contains(rootId, ";")) { String[] idParts = StringUtils.split(rootId, ";"); if (idParts.length != 3) throw new ServiceException("Malformed object id " + uri); id = new YaddaObjectID(idParts[0], idParts[2], idParts[1]); } else { id = new YaddaObjectID(rootId); } ArchiveObjectPath path = new ArchiveObjectPath(id, pathParts); return path; }
for (ContentFile location : content.getLocations()) { if ((ContentFile.TYPE_URI.equals(location.getAddressType()) || ContentFile.TYPE_URL.equals(location.getAddressType())) && ArchiveObjectPath.isValid(location.getAddress())) { for (ContentFile location : fulltext.getLocations()) { if ((ContentFile.TYPE_URI.equals(location.getAddressType()) || ContentFile.TYPE_URL.equals(location.getAddressType())) && ArchiveObjectPath.isValid(location.getAddress())) { try { URI uri = new URI(location.getAddress());
protected String contentPathToArchiveUri(String addr) throws Exception { String[] chunks = StringUtils.split(addr, "\\/"); List<String> chunkList = new LinkedList<String>(); boolean wasFirst = false; for (String chunk : chunks) { if (wasFirst && !chunk.startsWith("dsc_")) { chunkList.add(chunk); } wasFirst = true; } String firstChunk = chunkList.get(0); chunkList.remove(0); String[] internalChunks = chunkList .toArray(new String[chunkList.size()]); ArchiveObjectPath path = new ArchiveObjectPath(new YaddaObjectID( firstChunk), internalChunks); return path.encode(); }
if (uri!=null) { List<StorageOperation> result = new ArrayList<StorageOperation>(); if (!ArchiveObjectPath.isValid(uri)) { log.debug(uri + " is not an object from the yadda archive (probably external object)"); return null;
@Override public Set<DocumentAttachment> call() throws Exception { ArchiveObjectPath archivePath = ArchiveObjectPath.decode(path); ArchiveObject2Meta aObject = archiveFacadeProvider.getArchiveFacade().queryUniqueObject(archivePath, true); if (aObject == null) { throw new InvalidAttachmentException(path, "Attachment not available "); } ArchiveObjectFacade objectFacade = archiveFacadeProvider.getArchiveFacade().getObjectWithAllParts(aObject.getId(), true); Set<DocumentAttachment> attachments = new HashSet<DocumentAttachment>(); Collection<ArchiveContentPartFacade> parts = objectFacade.getParts(); try { for (ArchiveContentPartFacade partFacade : parts) { byte[] bytes = IOUtils.toByteArray(partFacade.getData()); DocumentAttachment documentAttachment = new DocumentAttachment(parent, partFacade.getId(), partFacade.getId(), partFacade.getSize(), partFacade.getMime(), bytes, false); documentAttachment.getProperties().put(ImporterConstants.PROPERTY_REMOTE_SOURCE_URL, path); attachments.add(documentAttachment); } } finally { closeFacades(parts); } return attachments; }
public String contentPathToArchiveUri(String addr) throws Exception { if (isAlreadyArchiveUri(addr)) { return addr; } String[] chunks = StringUtils.split(addr, "\\/"); boolean isNewPath = chunks[0].equalsIgnoreCase(BasicPackConstants.NEW_CONTENT_DIRECTORY); if (isNewPath) { List<String> chunkList = new LinkedList<String>(); boolean wasFirst = false; for (String chunk : chunks) { if (wasFirst && !chunk.startsWith("dsc_")) { chunkList.add(chunk); } wasFirst = true; } String firstChunk = chunkList.get(0); chunkList.remove(0); String[] internalChunks = chunkList.toArray(new String[chunkList.size()]); ArchiveObjectPath path = new ArchiveObjectPath(new YaddaObjectID(firstChunk), internalChunks); encodeIfNotEncoded(path); return path.encode(); } else { if (chunks.length > 2) { chunks = new String[]{chunks[0], chunks[chunks.length - 1]}; } ArchiveObjectPath path = new ArchiveObjectPath(new YaddaObjectID(importId), chunks); encodeIfNotEncoded(path); return path.encode(); } }
private void fillContent(final CatalogElement ce, final SElement sElement) throws YaddaException { // content files if (ce.getElement().getContents() != null && !ce.getElement().getContents().isEmpty()) { for (final Content content : ce.getElement().getContents()) { for (final ContentFile location : content.getLocations()) { final String fileAddress = location.getAddress(); if (ArchiveObjectPath.isValid(fileAddress)) { sElement.hasContent(true); } else { sElement.setRemoteContent(true); } } } // content licenses if (!Utils.emptyCollection(ce.getContentLicenses())) { for (final String license : ce.getContentLicenses()) { sElement.addContentLicense(license); } } } fillRemoteContent(ce, sElement); }
public List<String> listErrorDumps() throws Exception { ArchiveObject2Meta dumpDirectoryMeta = archiveFacade.queryUniqueObject(ERROR_DUMP_OBJECT_PATH, true); if (dumpDirectoryMeta == null) return Collections.emptyList(); ArchiveObjectFacade dumpDirectory = archiveFacade.getObject(dumpDirectoryMeta.getId(), null, true); List<String> dumpList = new LinkedList<String>(); for (Map.Entry<String, List<YaddaObjectID>> children : dumpDirectory.getChildren().entrySet()) { for (YaddaObjectID child : children.getValue()) { ArchiveObjectFacade childObject = archiveFacade.getObject(child, null, false); if (!childObject.getStatus().isDeleted()) { ArchiveObjectPath dumpPath = new ArchiveObjectPath(ERROR_DUMP_OBJECT_PATH, children.getKey()); dumpList.add(dumpPath.encode()); } } } return dumpList; }