/** * Extracts {@code YElement} from {@code Document}. * * @param document, * {@code Document} used to {@code YElement} extraction. @return, * null if the {@code YElement} could not be extracted from given * {@code Document}. Or extracted {@code YElement}. */ public static YElement getYElement(Document document) { YExportable exportable = document.getMetadata(); if (!(exportable instanceof YElement)) { return null; } return (YElement) exportable; }
private YElement fetchElement(DocumentRepository repository, String identity) { NativeDocument fetchDocument = repository.fetchDocument(identity); Document document = (Document) fetchDocument; YElement element = (YElement) document.getMetadata(); return element; }
private YElement fetchYElement(final String id) { NativeDocument document = documentRepository.fetchDocument(id); if(document != null && document instanceof Document){ return (YElement) ((Document)document).getMetadata(); } return null; }
private YElement fetchElement(DocumentRepository repository, String identity) { NativeDocument fetchDocument = repository.fetchDocument(identity); Document document = (Document) fetchDocument; YElement element = (YElement) document.getMetadata(); return element; }
@SuppressWarnings("unused") private void verify(String resourceId, String userId) { NativeDocument document = repository.fetchDocument(resourceId); if(document instanceof Document){ YElement element = (YElement) ((Document) document).getMetadata(); boolean result = contentEditor.canBeExported(userId, element); System.out.println("result canBeExported("+userId+", "+resourceId+")="+result); } }
@Override public String fetchMetadataAsXml(String id) { Document document = (Document) documentRepository.fetchDocument(id); YExportable metadata = document.getMetadata(); String xml = writerSupport.write(metadata, BwmetaTransformerConstants.FAST_TRANSFORMER); return xml; }
private static void writeDataToZipFile(Iterator<Record> itr, String zipFile) { logger.info("starting zipFile {}", zipFile); try { FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(fos); int count = 0; while (itr.hasNext() && count < FILES_PER_ZIP) { Document document = transformer.apply(itr.next()); logger.debug("zipFile {} document {}", zipFile, document.getId()); ZipEntry ze = new ZipEntry(bwmetaStorePath(document)); zos.putNextEntry(ze); String data = writerSupport.write(document.getMetadata()); zos.write(data.getBytes()); count++; } zos.closeEntry(); zos.close(); } catch (IOException ex) { logger.error("error", ex); } }
private Mets createMets(String resourceId) { YElement element = (YElement) getDocument(resourceId).getMetadata(); Mets mets = transformer.transform(element); return mets; }
private boolean fixContentType(String id, DocumentRepository repository) { try { NativeDocument fetchDocument = repository.fetchDocument(id); Document document = (Document) fetchDocument; YElement element = (YElement) document.getMetadata(); boolean fixed = false; fixed = fixContent(element); if (fixed) { // System.out.println("Element "+id+" fixed"); saveDocumentWithElement(repository, document, element); return true; } else { // System.out.println("Unable to fix element "+id); } } catch (Exception e) { e.printStackTrace(); } return false; }
@Override public ElementContent readContent(String userId, String resourceId, String contentId) { verifyAccessRight(userId, resourceId); YElement element = (YElement) getDocument(resourceId).getMetadata(); return contentReader.readContentFromRecord(contentId, element); }
public void readYElement(String resourceId) { DocumentRepository repository = DefaultDocumentRepositoryBuilder.buildRepository(store); Document doc = (Document) repository.fetchDocument(resourceId); YExportable metadata = doc.getMetadata(); YElement element = (YElement) metadata; System.out.println(element.getOneName().getText()); }
private void tryRecord(NativeDocument document) { // try { System.out.println("trying..." + document.getId()); YElement element = (YElement) ((Document) document).getMetadata(); StringBuilder textBuilder = new StringBuilder(); String title = fetchTitle(element); textBuilder.append(title).append("."); System.out.println("title=" + title); buildWithPlainText(textBuilder, document, element); // System.out.println("text="+textBuilder.substring(0, 300)); String finalText = textBuilder.toString(); // List<String> soncaKeywords = trySoncaKeywords(element, // finalText); List<String> pwKeywords = tryPwKeywords(finalText); writeResult(element.getId(), title, finalText.length(), pwKeywords); writer.flush(); // List<String> keywords = // metadataGenerator.generateKeywords(YLanguage.Polish, // textBuilder.toString()); } catch (Exception e) { e.printStackTrace(); } }
NativeDocument fetchDocument = repository.fetchDocument(id); Document document = (Document) fetchDocument; YElement element = (YElement) document.getMetadata(); boolean fixed = false;
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); } }
YElement element = (YElement) document.getMetadata();
NativeDocument document = documentFactory.getDocument(record); if(document instanceof Document){ String bwmeta = writerSupport.write(((Document) document).getMetadata()); saveBwmeta(record.getIdentifier().getUid(), bwmeta);
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); }
@Override public Document process(final Document document) { try { YExportable metadata = document.getMetadata(); if (metadata instanceof YElement) { YElement element = (YElement) metadata; structureBuilder.enrich(element); } else { problemHandler.handleProblem(LogSeverity.WARN, document.getId(), "YExportable", "metadata not YElement"); } } catch (BwmetaValidationException e) { problemHandler.handleProblem(LogSeverity.WARN, document.getId(), e.getValidationType(), e); } return document; } }
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; }