List of usage examples for java.util Objects nonNull
public static boolean nonNull(Object obj)
From source file:org.kitodo.production.process.TiffHeaderGenerator.java
/** * Get tiff header type from config Opac if the doctype should be specified. * * @param docType/*from w ww . j a v a 2s . c om*/ * for tiff header * @return tif header type */ private String getTifHeaderType(String docType) throws ProcessGenerationException { try { ConfigOpacDoctype configOpacDoctype = ConfigOpac.getDoctypeByName(docType); if (Objects.nonNull(configOpacDoctype)) { return configOpacDoctype.getTifHeaderType(); } } catch (FileNotFoundException e) { throw new ProcessGenerationException( MessageFormat.format(Helper.getTranslation(ERROR_READ), Helper.getTranslation(OPAC_CONFIG)), e); } return ""; }
From source file:org.kitodo.production.helper.metadata.ImageHelper.java
/** * Markus baut eine Seitenstruktur aus den vorhandenen Images --- Steps - * ---- Validation of images compare existing number images with existing * number of page DocStructs if it is the same don't do anything if * DocStructs are less add new pages to physicalDocStruct if images are less * delete pages from the end of pyhsicalDocStruct. *//* w w w.j av a2 s. co m*/ public void createPagination(Process process, URI directory) { LegacyDocStructHelperInterface physicalStructure = this.mydocument.getPhysicalDocStruct(); LegacyDocStructHelperInterface logicalStructure = this.mydocument.getLogicalDocStruct(); List<LegacyDocStructHelperInterface> allChildren = logicalStructure.getAllChildren(); while (logicalStructure.getDocStructType().getAnchorClass() != null && Objects.nonNull(allChildren) && !allChildren.isEmpty()) { logicalStructure = allChildren.get(0); } // the physical structure tree is only created if it does not exist yet if (Objects.isNull(physicalStructure)) { physicalStructure = createPhysicalStructure(process); this.mydocument.setPhysicalDocStruct(physicalStructure); } if (Objects.isNull(directory)) { checkIfImagesValid(process.getTitle(), ServiceManager.getProcessService().getImagesTifDirectory(true, process.getId(), process.getTitle(), process.getProcessBaseUri())); } else { checkIfImagesValid(process.getTitle(), directory); // fileService.getProcessSubTypeURI(process, ProcessSubType.IMAGE, null).resolve(directory)); } // retrieve existing pages/images LegacyLogicalDocStructTypeHelper newPage = this.myPrefs.getDocStrctTypeByName("page"); List<LegacyDocStructHelperInterface> oldPages = physicalStructure .getAllChildrenByTypeAndMetadataType("page", "*"); if (Objects.isNull(oldPages)) { oldPages = new ArrayList<>(); } // add new page/images if necessary if (oldPages.size() == this.myLastImage) { return; } String defaultPagination = ConfigCore .getParameterOrDefaultValue(ParameterCore.METS_EDITOR_DEFAULT_PAGINATION); Map<String, LegacyDocStructHelperInterface> assignedImages = new HashMap<>(); List<LegacyDocStructHelperInterface> pageElementsWithoutImages = new ArrayList<>(); if (physicalStructure.getAllChildren() != null && !physicalStructure.getAllChildren().isEmpty()) { for (LegacyDocStructHelperInterface page : physicalStructure.getAllChildren()) { if (page.getImageName() != null) { URI imageFile; if (Objects.isNull(directory)) { imageFile = ServiceManager .getProcessService().getImagesTifDirectory(true, process.getId(), process.getTitle(), process.getProcessBaseUri()) .resolve(page.getImageName()); } else { imageFile = fileService.getProcessSubTypeURI(process, ProcessSubType.IMAGE, null) .resolve(page.getImageName()); } if (fileService.fileExist(imageFile)) { assignedImages.put(page.getImageName(), page); } else { throw new UnsupportedOperationException("Dead code pending removal"); } } else { pageElementsWithoutImages.add(page); } } } List<URI> imagesWithoutPageElements = getImagesWithoutPageElements(process, assignedImages); // handle possible cases // case 1: existing pages but no images (some images are removed) if (!pageElementsWithoutImages.isEmpty() && imagesWithoutPageElements.isEmpty()) { for (LegacyDocStructHelperInterface pageToRemove : pageElementsWithoutImages) { physicalStructure.removeChild(pageToRemove); throw new UnsupportedOperationException("Dead code pending removal"); } } else if (pageElementsWithoutImages.isEmpty() && !imagesWithoutPageElements.isEmpty()) { // case 2: no page docs but images (some images are added) int currentPhysicalOrder = assignedImages.size(); for (URI newImage : imagesWithoutPageElements) { LegacyDocStructHelperInterface dsPage = this.mydocument.createDocStruct(newPage); // physical page no physicalStructure.addChild(dsPage); currentPhysicalOrder++; dsPage.addMetadata(createMetadataForPhysicalPageNumber(currentPhysicalOrder)); // logical page no dsPage.addMetadata(createMetadataForLogicalPageNumber(currentPhysicalOrder, defaultPagination)); logicalStructure.addReferenceTo(dsPage, "logical_physical"); // image name dsPage.addContentFile(createContentFile(newImage)); } } else { // case 3: empty page docs and unassinged images for (LegacyDocStructHelperInterface page : pageElementsWithoutImages) { if (!imagesWithoutPageElements.isEmpty()) { // assign new image name to page URI newImageName = imagesWithoutPageElements.get(0); imagesWithoutPageElements.remove(0); page.addContentFile(createContentFile(newImageName)); } else { // remove page physicalStructure.removeChild(page); throw new UnsupportedOperationException("Dead code pending removal"); } } if (!imagesWithoutPageElements.isEmpty()) { // create new page elements int currentPhysicalOrder = physicalStructure.getAllChildren().size(); for (URI newImage : imagesWithoutPageElements) { LegacyDocStructHelperInterface dsPage = this.mydocument.createDocStruct(newPage); // physical page no physicalStructure.addChild(dsPage); currentPhysicalOrder++; dsPage.addMetadata(createMetadataForPhysicalPageNumber(currentPhysicalOrder)); // logical page no dsPage.addMetadata(createMetadataForLogicalPageNumber(currentPhysicalOrder, defaultPagination)); logicalStructure.addReferenceTo(dsPage, "logical_physical"); // image name dsPage.addContentFile(createContentFile(newImage)); } } } int currentPhysicalOrder = 1; LegacyMetadataTypeHelper mdt = this.myPrefs.getMetadataTypeByName("physPageNumber"); if (physicalStructure.getAllChildrenByTypeAndMetadataType("page", "*") != null) { for (LegacyDocStructHelperInterface page : physicalStructure.getAllChildrenByTypeAndMetadataType("page", "*")) { List<? extends LegacyMetadataHelper> pageNoMetadata = page.getAllMetadataByType(mdt); if (Objects.isNull(pageNoMetadata) || pageNoMetadata.isEmpty()) { currentPhysicalOrder++; break; } for (LegacyMetadataHelper pageNo : pageNoMetadata) { pageNo.setStringValue(String.valueOf(currentPhysicalOrder)); } currentPhysicalOrder++; } } }
From source file:org.kitodo.production.process.TitleGenerator.java
private String getCurrentValue(String metadataTag) { int counter = 0; for (AdditionalField field : this.additionalFields) { if (field.isAutogenerated() && field.getValue().isEmpty()) { field.setValue(String.valueOf(System.currentTimeMillis() + counter)); counter++;/*from w w w.j a v a 2 s . co m*/ } String metadata = field.getMetadata(); if (Objects.nonNull(metadata) && metadata.equals(metadataTag)) { return field.getValue(); } } return ""; }
From source file:org.kitodo.dataformat.access.DivXmlElementAccess.java
/** * Constructor to read a structure from METS. * * @param div// w ww . j a va 2s . c om * METS {@code <div>} element from which the structure is to be * built * @param mets * METS data structure from which it is possible to determine * what kind of metadata section is linked * @param mediaUnitsMap * From this map, the media units are read, which must be * referenced here by their ID. */ DivXmlElementAccess(DivType div, Mets mets, Map<String, Set<FileXmlElementAccess>> mediaUnitsMap) { super(); super.setLabel(div.getLABEL()); for (Object mdSecType : div.getDMDID()) { super.getMetadata().addAll(readMetadata((MdSecType) mdSecType, MdSec.DMD_SEC)); } for (Object mdSecType : div.getADMID()) { super.getMetadata() .addAll(readMetadata((MdSecType) mdSecType, amdSecTypeOf(mets, (MdSecType) mdSecType))); } metsReferrerId = div.getID(); super.setOrderlabel(div.getORDERLABEL()); for (DivType child : div.getDiv()) { super.getChildren().add(new DivXmlElementAccess(child, mets, mediaUnitsMap)); } super.setType(div.getTYPE()); Set<FileXmlElementAccess> fileXmlElementAccesses = mediaUnitsMap.get(div.getID()); if (Objects.nonNull(fileXmlElementAccesses)) { for (FileXmlElementAccess fileXmlElementAccess : fileXmlElementAccesses) { if (Objects.nonNull(fileXmlElementAccess)) { super.getViews().add(new AreaXmlElementAccess(fileXmlElementAccess).getView()); } } } super.setLink(MptrXmlElementAccess.getLinkFromDiv(div)); }
From source file:org.kitodo.dataformat.access.MetsXmlElementAccess.java
/** * Creates a workpiece from a METS XML structure. Due to limitations of the * API, this can only be done by calling {@link #read(InputStream)} and then * replacing the content of the current editor, but at least the * implementation is clean.//w ww. j a v a 2s .c om * * @param mets * METS XML structure to read */ private MetsXmlElementAccess(Mets mets) { this(); MetsHdr metsHdr = mets.getMetsHdr(); if (Objects.nonNull(metsHdr)) { workpiece.setCreationDate(metsHdr.getCREATEDATE().toGregorianCalendar()); for (Agent agent : metsHdr.getAgent()) { workpiece.getEditHistory().add(new AgentXmlElementAccess(agent).getProcessingNote()); } MetsDocumentID metsDocumentID = metsHdr.getMetsDocumentID(); if (Objects.nonNull(metsDocumentID)) { workpiece.setId(metsDocumentID.getID()); } } FileSec fileSec = mets.getFileSec(); Map<String, MediaVariant> useXmlAttributeAccess = fileSec != null ? fileSec.getFileGrp().parallelStream().map(UseXmlAttributeAccess::new) .collect(Collectors.toMap( newUseXmlAttributeAccess -> newUseXmlAttributeAccess.getMediaVariant().getUse(), UseXmlAttributeAccess::getMediaVariant)) : new HashMap<>(); Optional<StructMapType> optionalPhysicalStructMap = getStructMapsStreamByType(mets, "PHYSICAL").findFirst(); Map<String, FileXmlElementAccess> divIDsToMediaUnits = new HashMap<>(); if (optionalPhysicalStructMap.isPresent()) { DivType div = optionalPhysicalStructMap.get().getDiv(); FileXmlElementAccess fileXmlElementAccess = new FileXmlElementAccess(div, mets, useXmlAttributeAccess); MediaUnit mediaUnit = fileXmlElementAccess.getMediaUnit(); workpiece.setMediaUnit(mediaUnit); divIDsToMediaUnits.put(div.getID(), fileXmlElementAccess); readMeadiaUnitsTreeRecursive(div, mets, useXmlAttributeAccess, mediaUnit, divIDsToMediaUnits); } if (mets.getStructLink() == null) { mets.setStructLink(new StructLink()); } Map<String, Set<FileXmlElementAccess>> mediaUnitsMap = new HashMap<>(); for (Object smLinkOrSmLinkGrp : mets.getStructLink().getSmLinkOrSmLinkGrp()) { if (smLinkOrSmLinkGrp instanceof SmLink) { SmLink smLink = (SmLink) smLinkOrSmLinkGrp; mediaUnitsMap.computeIfAbsent(smLink.getFrom(), any -> new HashSet<FileXmlElementAccess>()); mediaUnitsMap.get(smLink.getFrom()).add(divIDsToMediaUnits.get(smLink.getTo())); } } workpiece.setRootElement(getStructMapsStreamByType(mets, "LOGICAL") .map(structMap -> new DivXmlElementAccess(structMap.getDiv(), mets, mediaUnitsMap)) .collect(Collectors.toList()).iterator().next()); }
From source file:com.mac.holdempoker.app.impl.util.HandMatrix.java
/** * ROYAL FLUSH// ww w .j a v a2s . c o m * * @return */ private HandRank aHandRank() { HandRank hr = bHandRank(); if (Objects.nonNull(hr)) { Card[] cards = hr.getHand(); // Arrays.sort(cards, this); if (cards[cards.length - 1].getRank().value() == 14 && cards[0].getRank().value() == 10) { return new SimpleHandRank(HandType.ROYAL_FLUSH, cards); } } return null; }
From source file:org.kitodo.production.services.data.LdapServerService.java
private String buildUserDN(User inUser) { String userDN = inUser.getLdapGroup().getUserDN(); userDN = userDN.replaceAll("\\{login\\}", inUser.getLogin()); if (Objects.nonNull(inUser.getLdapLogin())) { userDN = userDN.replaceAll("\\{ldaplogin\\}", inUser.getLdapLogin()); }//w w w . j a v a 2s. c o m userDN = userDN.replaceAll("\\{firstname\\}", inUser.getName()); userDN = userDN.replaceAll("\\{lastname\\}", inUser.getSurname()); return userDN; }
From source file:com.caricah.iotracah.server.mqttserver.netty.MqttServerImpl.java
@Override public void postProcess(IOTMessage ioTMessage) { switch (ioTMessage.getMessageType()) { case ConnectAcknowledgeMessage.MESSAGE_TYPE: ConnectAcknowledgeMessage conMessage = (ConnectAcknowledgeMessage) ioTMessage; /**//from w w w . j av a 2 s.c o m * Use the connection acknowledgement message to store session id for persistance. */ Channel channel = getChannel(ioTMessage.getConnectionId()); if (Objects.nonNull(channel)) { if (MqttConnectReturnCode.CONNECTION_ACCEPTED.equals(conMessage.getReturnCode())) { channel.attr(ServerImpl.REQUEST_SESSION_ID).set(ioTMessage.getSessionId()); } else { closeClient(ioTMessage.getConnectionId()); } } break; default: super.postProcess(ioTMessage); } }
From source file:com.thoughtworks.go.server.service.plugins.builder.DefaultPluginInfoBuilder.java
public NewPluginInfo pluginInfoFor(String pluginId) { return builders.values().stream().map(new Function<NewPluginInfoBuilder, NewPluginInfo>() { @Override//from w w w. j a v a2s. c om public NewPluginInfo apply(NewPluginInfoBuilder builder) { return builder.pluginInfoFor(pluginId); } }).filter(new Predicate<NewPluginInfo>() { @Override public boolean test(NewPluginInfo obj) { return Objects.nonNull(obj); } }).findFirst().orElse(null); }
From source file:org.kitodo.forms.WorkflowForm.java
/** * Save updated content of the diagram./*from w w w . ja va2 s .c om*/ */ private void saveFiles() { Map<String, String> requestParameterMap = FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap(); xmlDiagram = requestParameterMap.get("diagram"); if (Objects.nonNull(xmlDiagram)) { svgDiagram = StringUtils.substringAfter(xmlDiagram, "kitodo-diagram-separator"); xmlDiagram = StringUtils.substringBefore(xmlDiagram, "kitodo-diagram-separator"); saveXMLDiagram(); saveSVGDiagram(); } }