private void saveDocumentWithElement(DocumentRepository repository, Document document, YElement element) { document.setMetadata(element); repository.storeDocument(document, EventConstants.EVENT_TAG_NO_EVENT); }
private void addCoverAndOrMetadata(Document document, HarvestingResult harvestingResult) { YElement element = YElementUtils.getYElement(document); if (prepareDocumentCoverAndOrMetadata(document, harvestingResult, element)) { document.setMetadata(element); } }
@Override public void replaceMetadata(String id, String xml) { Document document = (Document) documentRepository.fetchDocument(id); YExportable element; element = YModelToolbox.retrieveFirstYElement(bwmetaDeserializer.parse(xml, null)); document.setMetadata(element); documentRepository.storeDocument(document, null); }
private void processDocument(Document document) { YExportable exportable = document.getMetadata(); if (!(exportable instanceof YElement)) { return; } YElement element = (YElement) exportable; try { if (transformer.modify(element)) { document.setMetadata(exportable); } } catch (Exception e) { problemHandler.handleProblem(LogSeverity.WARN, document.getId(), "enriching problem", e); } }
private boolean changeElementLevel(DocumentRepository repository, String identity) { NativeDocument fetchDocument = repository.fetchDocument(identity); Document document = (Document) fetchDocument; YElement element = (YElement) document.getMetadata(); String fixedCurrentLevel = HierarchyWithLevelIds.EXT_LEVEL_JOURNAL_ISSUE; String newTagValue = HierarchyWithLevelIds.EXT_HIERARCHY_JOURNAL + "=" + fixedCurrentLevel; document.addTagByKey("hierarchyLevel", newTagValue); YStructure structure = element.getStructure(HierarchyWithLevelIds.EXT_HIERARCHY_JOURNAL); YCurrent current = structure.getCurrent(); if (!HierarchyWithLevelIds.EXT_LEVEL_JOURNAL_VOLUME.equals(current.getLevel())) { System.out.println("current level is = "+current.getLevel()+" expected year. Won't fix"); return false; } else { current.setLevel(fixedCurrentLevel); document.setMetadata(element); repository.storeDocument(document, EventConstants.EVENT_TAG_NO_EVENT); return true; } }
public void writeContent(Document document, InputStream inputStream, String contentFormat) { YElement metadata = (YElement) document.getMetadata(); String contentPartName = addOrReplaceYContent(metadata, contentFormat); document.setMetadata(metadata); try { document.addBinaryAttachment(contentPartName, new InputStreamResource(inputStream)); } catch (IOException e) { throw new GeneralBusinessException("Encountered a problem while adding attachment: {} to document: {}", contentPartName, document.getId()); } repository.storeDocument(document, null); }
private PersistableAuthorship requestRemoveAuthorshipInternal(PersistableAuthorship authorship, String removeAuthorshipNote, boolean immediate) { authorshipUtil.changeStatus(authorship, AuthorshipStatus.REMOVE_REQUEST, removeAuthorshipNote); if (immediate) { Document document = (Document) repository.fetchDocument(authorship.getDocumentId()); YElement element = (YElement) document.getMetadata(); ValidationInfo info = validator.validate(document, authorshipMapping.apply(authorship)); if (!info.isValid()) { LOGGER.warn("Processing immediate remove authorship request: " + authorship + " failed with note: " + info.getNote()); } else if (!info.isAlreadyAssigned()) { LOGGER.warn("Trying to remove not existing association: " + authorship); } else { SetMultimap<String, String> personIdentities = HashMultimap.create(); YContributor contributor = BwmetaContributorUtils.getContributorById(authorship.getAuthorNoInDocument(), element); personIdentities.put(authorship.getUserId(), BwmetaContributorUtils.buildContributorId(authorship.getDocumentId(), contributor)); BwmetaContributorUtils.setContributorIdentity(contributor, null); document.setMetadata(element); authorship.setForced(true); repository.storeDocument(document, EventConstants.EVENT_TAG_NO_EVENT); } } authorship = authorshipRepository.saveAndFlush(authorship); if(authorship.getStatus() == AuthorshipStatus.REMOVE_REQUEST){ markForProcessing(authorship.getId()); } return authorship; }