List of usage examples for java.util Objects isNull
public static boolean isNull(Object obj)
From source file:org.restheart.handlers.schema.JsonSchemaCacheSingleton.java
private BsonDocument loadRaw(String schemaStoreDb, BsonValue schemaId) throws JsonSchemaNotFoundException { BsonDocument document = dbsDAO.getCollection(schemaStoreDb, RequestContext._SCHEMAS) .find(eq("_id", schemaId)).first(); if (Objects.isNull(document)) { String sid;/*from w ww . j a v a 2 s . com*/ try { sid = JsonUtils.getIdAsString(schemaId); } catch (UnsupportedDocumentIdException uide) { sid = schemaId.toString(); } throw new JsonSchemaNotFoundException("schema not found " + schemaStoreDb + "/" + sid); } // schemas are stored with escaped keys, need to unescape them JsonSchemaTransformer.unescapeSchema(document); return document; }
From source file:org.kitodo.production.process.field.AdditionalField.java
/** * Set document structure./* ww w .j a v a 2s.c o m*/ * * @param docStruct * String */ public void setDocStruct(String docStruct) { this.docStruct = docStruct; if (Objects.isNull(this.docStruct)) { this.docStruct = "topstruct"; } }
From source file:org.kitodo.data.elasticsearch.index.IndexRestClient.java
/** * Add list of documents to the index. This method will be used for add whole * table to the index. It performs asynchronous request. * * @param documentsToIndex/* ww w . j a v a2s .c om*/ * list of json documents to the index */ void addTypeAsync(Map<Integer, Map<String, Object>> documentsToIndex) { BulkRequest bulkRequest = prepareBulkRequest(documentsToIndex); ResponseListener responseListener = new ResponseListener(this.type, documentsToIndex.size()); highLevelClient.bulkAsync(bulkRequest, responseListener); synchronized (lock) { while (Objects.isNull(responseListener.getBulkResponse())) { try { lock.wait(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } } } }
From source file:cito.stomp.Frame.java
/** * Checks if the header is set on the frame. * /*w w w .j av a 2 s . c om*/ * @param header the header to check. * @return {@code true} if the frame contains the header. */ public boolean contains(Header header) { return !Objects.isNull(get(header)); }
From source file:org.apache.streams.cassandra.CassandraPersistWriter.java
@Override public void write(StreamsDatum streamsDatum) { ObjectNode node;/*from w w w. j av a 2 s. c om*/ if (streamsDatum.getDocument() instanceof String) { try { node = mapper.readValue((String) streamsDatum.getDocument(), ObjectNode.class); byte[] value = node.toString().getBytes(); String key = GuidUtils.generateGuid(node.toString()); if (!Objects.isNull(streamsDatum.getMetadata().get("id"))) { key = streamsDatum.getMetadata().get("id").toString(); } BoundStatement statement = insertStatement.bind(key, ByteBuffer.wrap(value)); insertBatch.add(statement); } catch (IOException ex) { LOGGER.warn("Failure adding object: {}", streamsDatum.getDocument().toString()); return; } } else { try { node = mapper.valueToTree(streamsDatum.getDocument()); byte[] value = node.toString().getBytes(); String key = GuidUtils.generateGuid(node.toString()); if (!Objects.isNull(streamsDatum.getId())) { key = streamsDatum.getId(); } BoundStatement statement = insertStatement.bind(key, ByteBuffer.wrap(value)); insertBatch.add(statement); } catch (Exception ex) { LOGGER.warn("Failure adding object: {}", streamsDatum.getDocument().toString()); return; } } flushIfNecessary(); }
From source file:org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerGroupsImpl.java
private List<String> getToscaPolicies(Resource resource, String resourceId) { Map<String, Object> properties = resource.getProperties(); if (Objects.isNull(properties) || Objects.isNull(properties.get("policies"))) { return Arrays.asList(ToscaPolicyType.PLACEMENT_ANTILOCATE.getDisplayName()); }//from ww w. j a v a2 s.com List policies = (List) properties.get("policies"); List<String> retList = new ArrayList<>(); policies.forEach(policy -> { if (!supportedPolicies.contains(policy)) { logger.warn( "Resource '" + resourceId + "'(" + resource.getType() + ") contains unsupported policy '" + policy.toString() + "'. This resource is been ignored during the translation"); } else { retList.add(getToscaPolicyByHotPolicy((String) policy)); } }); return retList; }
From source file:org.kitodo.api.dataformat.MediaUnit.java
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((mediaFiles == null) ? 0 : mediaFiles.hashCode()); result = prime * result + order;//w ww . ja va 2s.c o m result = prime * result + ((orderlabel == null) ? 0 : orderlabel.hashCode()); result = prime * result + (Objects.isNull(type) ? 0 : type.hashCode()); return result; }
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. *///from ww w . j a v a 2 s. c o 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.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager.java
/** * get the (cached) follow up TagName/*from w w w.j a v a2s. c o m*/ * * @return * * @throws TskCoreException */ public TagName getFollowUpTagName() throws TskCoreException { synchronized (autopsyTagsManagerLock) { if (Objects.isNull(followUpTagName)) { followUpTagName = getTagName(FOLLOW_UP); } return followUpTagName; } }
From source file:webfx.URLVerifier.java
private void discoverThroughHeaders() throws IOException, URISyntaxException { // relax redirections HttpGet httpGet = new HttpGet(location.toURI()); HttpClientContext httpcontext = HttpClientContext.create(); try (CloseableHttpResponse response = httpclient.execute(httpGet, httpcontext)) { // get mimetype via Content-Type http header Arrays.stream(response.getHeaders("Content-Type")).findFirst() .ifPresent(h -> this.contentType = h.getValue()); if (!Objects.isNull(contentType)) { contentType = contentType.contains(";") ? contentType.substring(0, contentType.indexOf(";")).trim() : contentType;//from w ww. ja v a 2 s .c om LOGGER.log(Level.INFO, "Final Content-Type: {0}", contentType); } else { LOGGER.log(Level.INFO, "Content-Type Header is Empty: {0}", Arrays.toString(response.getHeaders("Content-Type"))); // clear field b/c it was used inside lambda as temp var contentType = null; } // get filename via Content-Disposition http header Arrays.stream(response.getHeaders("Content-Disposition")).findFirst() .ifPresent(h -> this.pageName = h.getValue()); if (!Objects.isNull(pageName) && pageName.contains("filename=")) { pageName = pageName.substring(pageName.lastIndexOf("filename=") + 9); LOGGER.log(Level.INFO, "temporary page name: {0}", pageName); if (pageName.indexOf('.') > -1) { fileExtension = pageName.substring(pageName.indexOf('.') + 1).trim(); LOGGER.log(Level.INFO, "Final file extension: {0}", fileExtension); } pageName = pageName.substring(0, pageName.indexOf('.')).trim(); LOGGER.log(Level.INFO, "Final page name: {0}", pageName); } else { // clear field b/c it was used inside lambda as temp var pageName = null; } HttpHost target = httpcontext.getTargetHost(); List<URI> redirectLocations = httpcontext.getRedirectLocations(); URI _loc = URIUtils.resolve(httpGet.getURI(), target, redirectLocations); this.location = _loc.toURL(); LOGGER.log(Level.INFO, "Final HTTP location: {0}", _loc.toURL()); } }