/** * Creates a new facade with metadata and data about children copied from * specified metadata container. Without any parts. * @param src source of metadata */ public ArchiveObjectFacade(ArchiveObject2 src) { super(src); this.children = src.getChildren(); }
/** * Creates a copy of object metadata * @param src source metadata */ public ArchiveObject2Meta(ArchiveObject2Meta src) { super(src); this.setParentId(src.getParentId()); this.setParentRelationName(src.getParentRelationName()); this.setType(src.getType()); this.setStructureType(src.getStructureType()); }
public static boolean isValid(String uri) { try { ArchiveObjectPath.decode(uri); return true; } catch (URISyntaxException e) { return false; } catch (ServiceException e) { return false; } }
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; }
public String storeDump(ChunkErrorDump dump) throws Exception { if (archiveFacade.queryUniqueObject(SYSTEM_OBJECT_PATH, true) == null) { ArchiveObjectFacade object = new ArchiveObjectFacade( new ArchiveObject2Meta(SYSTEM_OBJECT_PATH.getRootId(), SYSTEM_OBJECT_TYPE, "nothing", null)); storageFacade.saveObject(SYSTEM_OBJECT_PATH.encode(), object, null, null); if (archiveFacade.queryUniqueObject(ERROR_DUMP_OBJECT_PATH, true) == null) { ArchiveObjectFacade object = new ArchiveObjectFacade( 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); ArchiveObjectFacade object = new ArchiveObjectFacade( new ArchiveObject2Meta(new YaddaObjectID(id), ERROR_DUMP_TYPE, "nothing", null)); object.addPart(PART_TYPE_DUMP, MIME_JAVA_SERIALIZED_OBJECT , dumpIs); storageFacade.saveObject(path.encode(), object, null, null); return path.encode();
@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; }
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; archiveFacade.queryObjects(uri, true); if (metasIt!=null) { while (metasIt.hasNext()) { ArchiveObject2Meta meta = metasIt.next(); Set<String> sourceLicenses = LicenseProcessorModuleHelper.extractLicenses( meta.getTags(), SecurityConstants.TAG_LICENSE_PREFIX); TagOperation tagOp = tagOperationCreator.prepareTagOperation( sourceLicenses, SecurityConstants.TAG_LICENSE_PREFIX, ". Dropping tags: " + logArrayContent(tagOp.getTagsToRemove()) + ". Already existing tags: " + logArrayContent(meta.getTags())); ArchiveObjectFacade archObjFacade = new ArchiveObjectFacade(meta); archObjFacade.setTags(tagOp.getTagsToAdd()); result.add(storageFacade.buildSaveOperation( uri, archObjFacade, null, tagOp.getTagsToRemove())); } else { log.debug("no changes in tags for uri: " + uri + ", meta id: " + ( (meta.getId()!=null && meta.getId().getId()!=null) ?meta.getId().getId():null));
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 void removeDump(String dumpId) throws Exception { ArchiveObject2Meta dumpMeta = archiveFacade.queryUniqueObject(dumpId, false); if (dumpMeta == null) return; storageFacade.deleteObject(dumpMeta.getId()); }
/** * Registers single file content into given storage location using parent and tags. * Returns {@link YaddaObjectID} of registered document. * @param file * @param yarPath * @param parentId * @param tags * @return {@link YaddaObjectID} of registered document * @throws ServiceException * @throws FileNotFoundException */ protected YaddaObjectID registerFile(File file, String yarPath, YaddaObjectID parentId, String[] tags) throws ServiceException, FileNotFoundException { ArchiveObjectFacade currentPolicyMeta = new ArchiveObjectFacade(); currentPolicyMeta.setId(new YaddaObjectID(new UUIDGenerator().generate(null))); currentPolicyMeta.setType(ArchiveParamConstants.OBJECT_TYPE_FILE); currentPolicyMeta.setParentId(parentId); currentPolicyMeta.setTags(tags); currentPolicyMeta.addPart(predefinedPartType, predefinedMimeType, new FileInputStream(file)); StorageOperation currentOp = storageFacade.buildSaveOperation( yarPath, currentPolicyMeta, null, null); return storageFacade.executeOperation(currentOp); }
@Override public boolean addUserProfile(String userId) { try { archive.getObject(new YaddaObjectID(userId), null, false); return false; } catch (NotFoundException e) { ArchiveObjectFacade archiveObject; archiveObject = new ArchiveObjectFacade(); archiveObject.setId(new YaddaObjectID(userId)); archiveObject.setType(USER_PROFILE_TYPE); try { storage.saveObject(generateStorePath(userId), archiveObject, null, null); } catch (ServiceException e1) { String message = "Adding user profile for user " + userId + " not successfull."; logger.error(message, e1); throw new RuntimeException(message, e1); } return true; } catch (ServiceException e) { String message = "Fetching user profile for user " + userId + " not successfull."; logger.error(message, e); throw new RuntimeException(message, e); } }
/** * Checks whether node of given path already exists in archive. * Returns {@link YaddaObjectID} of found node. * * @param nodePath * @return {@link YaddaObjectID} of found node or * null if node not found or archiveFacade was not set * @throws ServiceException */ protected YaddaObjectID nodeExists(String nodePath) throws ServiceException { if (archiveFacade!=null) { ArchiveObject2Meta parentMeta = archiveFacade.queryUniqueObject(nodePath, true); return parentMeta!=null?parentMeta.getId():null; } else { log.warn("cannot verify if " + nodePath + " exists, " + "archiveFacade was not set!"); return null; } }
/** * 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(); }
/** * Finds collection id in archive object. * @param archiveObjId * @return collection id * @throws IndeterminateException */ protected String findCollectionTagInArchive(String archiveObjId) throws IndeterminateException { try { ArchiveObjectFacade archObjFacade = archiveFacade.getObject( new YaddaObjectID(archiveObjId), new String[0], false); for (String currentTag : archObjFacade.getTags()) { if (currentTag.startsWith(ACLConstants.COLLECTION_TAG_PREFIX)) { return currentTag; } } return null; } catch (ServiceException e) { throw new IndeterminateException("exception occured when " + "finding archive object for id: " + archiveObjId, e); } }
@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"); } }
void encodeIfNotEncoded(ArchiveObjectPath aop){ String[] t=aop.getPath(); for (int i=0; i< t.length; i++){ t[i]=encodeIfNotEncoded(t[i]); } }
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(); }
/** * 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; }
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(); } }