List of usage examples for java.util Objects nonNull
public static boolean nonNull(Object obj)
From source file:org.kitodo.export.ExportDms.java
private boolean exportImagesAndMetsToDestinationUri(Process process, LegacyMetsModsDigitalDocumentHelper gdzfile, URI destination, URI userHome) throws IOException { if (exportWithImages) { try {//from w w w . j ava 2 s .c o m directoryDownload(process, destination); } catch (IOException | InterruptedException | RuntimeException e) { if (Objects.nonNull(exportDmsTask)) { exportDmsTask.setException(e); } else { Helper.setErrorMessage(ERROR_EXPORT, new Object[] { process.getTitle() }, logger, e); } return false; } } /* * export the file to the desired location, either directly into the import * folder or into the user's home, then start the import thread */ if (process.getProject().isUseDmsImport()) { asyncExportWithImport(process, gdzfile, userHome); } else { exportWithoutImport(process, gdzfile, userHome); } return true; }
From source file:com.mac.holdempoker.app.impl.util.HandMatrix.java
/** * FLUSH/*from ww w . ja va 2 s . co m*/ * * @return */ private HandRank eHandRank() { Entry<Suit, Rank[]> flush = getFlushEntry(); if (Objects.isNull(flush)) { return null; } Rank[] ranks = flush.getValue(); Arrays.sort(ranks, rc); CollectionUtils.reverseArray(ranks); List<Card> cards = new ArrayList(); for (int i = 0; i < 13; i++) { Rank r = ranks[i]; if (Objects.nonNull(r) && cards.size() < 5) { cards.add(makeCard(flush.getKey(), r)); } } Collections.sort(cards, this); return new SimpleHandRank(HandType.FLUSH, cards.toArray(new Card[5])); }
From source file:com.caricah.iotracah.core.worker.DumbWorker.java
/** * Provides the Observer with a new item to observe. * <p>// w ww. j a va2 s .c o m * The {@link com.caricah.iotracah.core.modules.Server} may call this method 0 or more times. * <p> * The {@code Observable} will not call this method again after it calls either {@link #onCompleted} or * {@link #onError}. * * @param iotMessage the item emitted by the Observable */ @Override public void onNext(IOTMessage iotMessage) { getExecutorService().submit(() -> { log.info(" onNext : received {}", iotMessage); try { IOTMessage response = null; switch (iotMessage.getMessageType()) { case ConnectMessage.MESSAGE_TYPE: ConnectMessage connectMessage = (ConnectMessage) iotMessage; response = ConnectAcknowledgeMessage.from(connectMessage.isDup(), connectMessage.getQos(), connectMessage.isRetain(), connectMessage.getKeepAliveTime(), MqttConnectReturnCode.CONNECTION_ACCEPTED); break; case SubscribeMessage.MESSAGE_TYPE: SubscribeMessage subscribeMessage = (SubscribeMessage) iotMessage; List<Integer> grantedQos = new ArrayList<>(); subscribeMessage.getTopicFilterList().forEach(topic -> { String topicKey = quickCheckIdKey("", Arrays.asList(topic.getKey().split(Constant.PATH_SEPARATOR))); Set<String> channelIds = subscriptions.get(topicKey); if (Objects.isNull(channelIds)) { channelIds = new HashSet<>(); } channelIds.add(subscribeMessage.getConnectionId()); subscriptions.put(topicKey, channelIds); grantedQos.add(topic.getValue()); }); response = SubscribeAcknowledgeMessage.from(subscribeMessage.getMessageId(), grantedQos); break; case UnSubscribeMessage.MESSAGE_TYPE: UnSubscribeMessage unSubscribeMessage = (UnSubscribeMessage) iotMessage; response = UnSubscribeAcknowledgeMessage.from(unSubscribeMessage.getMessageId()); break; case Ping.MESSAGE_TYPE: response = iotMessage; break; case PublishMessage.MESSAGE_TYPE: PublishMessage publishMessage = (PublishMessage) iotMessage; Set<String> matchingTopics = getMatchingSubscriptions("", publishMessage.getTopic()); for (String match : matchingTopics) { Set<String> channelIds = subscriptions.get(match); if (Objects.nonNull(channelIds)) { channelIds.forEach(id -> { PublishMessage clonePublishMessage = publishMessage.cloneMessage(); clonePublishMessage.copyTransmissionData(iotMessage); clonePublishMessage.setConnectionId(id); pushToServer(clonePublishMessage); }); } } if (MqttQoS.AT_MOST_ONCE.value() == publishMessage.getQos()) { break; } else if (MqttQoS.AT_LEAST_ONCE.value() == publishMessage.getQos()) { response = AcknowledgeMessage.from(publishMessage.getMessageId()); break; } case PublishReceivedMessage.MESSAGE_TYPE: case ReleaseMessage.MESSAGE_TYPE: case CompleteMessage.MESSAGE_TYPE: case DisconnectMessage.MESSAGE_TYPE: case AcknowledgeMessage.MESSAGE_TYPE: default: DisconnectMessage disconnectMessage = DisconnectMessage.from(true); disconnectMessage.copyTransmissionData(iotMessage); throw new ShutdownException(disconnectMessage); } if (Objects.nonNull(response)) { response.copyTransmissionData(iotMessage); pushToServer(response); } } catch (ShutdownException e) { IOTMessage response = e.getResponse(); if (Objects.nonNull(response)) { pushToServer(response); } } catch (Exception e) { log.error(" onNext : Serious error that requires attention ", e); } }); }
From source file:org.kitodo.dataformat.access.DivXmlElementAccess.java
/** * Creates a METS {@code <div>} element from this structure. * * @param mediaUnitIDs/*from www . j ava2 s . c o m*/ * the assigned identifier for each media unit so that the link * pairs of the struct link section can be formed later * @param smLinkData * the link pairs of the struct link section are added to this * list * @param mets * the METS structure in which the meta-data is added * @return a METS {@code <div>} element */ DivType toDiv(Map<MediaUnit, String> mediaUnitIDs, LinkedList<Pair<String, String>> smLinkData, Mets mets) { DivType div = new DivType(); div.setID(metsReferrerId); div.setLABEL(super.getLabel()); div.setORDERLABEL(super.getOrderlabel()); div.setTYPE(super.getType()); smLinkData.addAll(super.getViews().parallelStream().map(View::getMediaUnit).map(mediaUnitIDs::get) .map(mediaUnitId -> Pair.of(metsReferrerId, mediaUnitId)).collect(Collectors.toList())); Optional<MdSecType> optionalDmdSec = createMdSec(super.getMetadata(), MdSec.DMD_SEC); if (optionalDmdSec.isPresent()) { MdSecType dmdSec = optionalDmdSec.get(); String name = metsReferrerId + ':' + MdSec.DMD_SEC.toString(); dmdSec.setID(UUID.nameUUIDFromBytes(name.getBytes(StandardCharsets.UTF_8)).toString()); mets.getDmdSec().add(dmdSec); div.getDMDID().add(dmdSec); } Optional<AmdSecType> optionalAmdSec = createAmdSec(super.getMetadata(), metsReferrerId, div); if (optionalAmdSec.isPresent()) { AmdSecType admSec = optionalAmdSec.get(); mets.getAmdSec().add(admSec); } if (Objects.nonNull(super.getLink())) { MptrXmlElementAccess.addMptrToDiv(super.getLink(), div); } for (IncludedStructuralElement subincludedStructuralElement : super.getChildren()) { div.getDiv().add( new DivXmlElementAccess(subincludedStructuralElement).toDiv(mediaUnitIDs, smLinkData, mets)); } return div; }
From source file:org.kitodo.production.services.file.FileService.java
/** * Gets and returns the name of the user whose context the code is currently * running in, to request or assume meta-data locks for that user. The name * of the user is returned, or System?, if the code is running in the * system context (i.e. not running under a registered user). * * @return the user name for locks/*from ww w . ja v a2 s. c om*/ */ public static String getCurrentLockingUser() { UserService userService = ServiceManager.getUserService(); User currentUser = userService.getAuthenticatedUser(); return Objects.nonNull(currentUser) ? userService.getFullName(currentUser) : SYSTEM_LOCKING_USER; }
From source file:org.eclipse.winery.repository.rest.resources.MainResource.java
@POST @Consumes(MediaType.MULTIPART_FORM_DATA) @ApiOperation(value = "Imports the given CSAR (sent by simplesinglefileupload.jsp)") @ApiResponses(value = {//from w ww . jav a 2s . c o m @ApiResponse(code = 200, message = "success", responseHeaders = @ResponseHeader(description = "If the CSAR could be partially imported, the points where it failed are returned in the body")) }) // @formatter:off public Response importCSAR(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("overwrite") @ApiParam(value = "true: content of CSAR overwrites existing content. false (default): existing content is kept") Boolean overwrite, @FormDataParam("validate") @ApiParam(value = "true: validates the hash of the manifest file with the one stored in the accountability layer") Boolean validate, @Context UriInfo uriInfo) { LocalDateTime start = LocalDateTime.now(); // @formatter:on CsarImporter importer = new CsarImporter(); CsarImportOptions options = new CsarImportOptions(); options.setOverwrite((overwrite != null) && overwrite); options.setAsyncWPDParsing(false); options.setValidate((validate != null) && validate); ImportMetaInformation importMetaInformation; try { importMetaInformation = importer.readCSAR(uploadedInputStream, options); } catch (Exception e) { return Response.serverError().entity("Could not import CSAR").entity(e.getMessage()).build(); } if (importMetaInformation.errors.isEmpty()) { if (options.isValidate()) { return Response.ok(importMetaInformation, MediaType.APPLICATION_JSON).build(); } else if (Objects.nonNull(importMetaInformation.entryServiceTemplate)) { URI url = uriInfo.getBaseUri() .resolve(RestUtils.getAbsoluteURL(importMetaInformation.entryServiceTemplate)); LOGGER.debug("CSAR import lasted {}", Duration.between(LocalDateTime.now(), start).toString()); return Response.created(url).build(); } else { LOGGER.debug("CSAR import lasted {}", Duration.between(LocalDateTime.now(), start).toString()); return Response.noContent().build(); } } else { LOGGER.debug("CSAR import lasted {}", Duration.between(LocalDateTime.now(), start).toString()); // In case there are errors, we send them as "bad request" return Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON) .entity(importMetaInformation).build(); } }
From source file:org.kitodo.production.forms.MassImportForm.java
private void removeFiles() throws IOException { if (Objects.nonNull(this.importFile)) { Files.delete(this.importFile.toPath()); this.importFile = null; }/*from w w w. j a v a2s .c o m*/ if (Objects.nonNull(selectedFilenames) && !selectedFilenames.isEmpty()) { this.plugin.deleteFiles(this.selectedFilenames); } }
From source file:org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerImpl.java
private boolean isSchedulerHintsPropExist(Map<String, Object> properties) { return !MapUtils.isEmpty(properties) && Objects.nonNull(properties.get("scheduler_hints")); }
From source file:org.kitodo.production.services.data.BatchService.java
/** * The function getLabel() returns a readable label for the batch, which is * either its title, if defined, or, for batches not having a title (in * recent versions of Production, batches didnt support titles) its ancient * label, consisting of the prefix Batch ? (in the desired translation) * together with its id number.//from www .j a va 2 s. c o m * * @return a readable label for the batch */ public String getLabel(BatchDTO batch) { return Objects.nonNull(batch.getTitle()) ? batch.getTitle() : getNumericLabel(batch); }
From source file:org.openecomp.sdc.translator.services.heattotosca.impl.NovaToVolResourceConnection.java
@Override void addRequirementToConnectResources(Map.Entry<String, RequirementDefinition> entry, List<String> paramNames) { String paramName = paramNames.get(0); Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil.extractAttachedResourceId(translateTo, paramName);//from w w w. jav a2 s .c o m String node; if (!attachedResourceId.isPresent()) { return; } AttachedResourceId attachedResource = attachedResourceId.get(); if (attachedResource.isGetResource()) { String volTranslatedId = (String) attachedResource.getTranslatedId(); Resource volServerResource = HeatToToscaUtil.getResource(translateTo.getHeatOrchestrationTemplate(), volTranslatedId, translateTo.getHeatFileName()); if (!StringUtils.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(), volServerResource.getType())) { logger.warn("Volume attachment used from nested resource " + translateTo.getResourceId() + " is pointing to incorrect resource type(" + volServerResource.getType() + ") for relation through the parameter '" + paramName + "." + " The connection to the volume is ignored. " + "Supported types are: " + HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()); return; } node = volTranslatedId; createRequirementAssignment(entry, node, substitutionNodeTemplate); } else if (attachedResource.isGetParam()) { TranslatedHeatResource shareResource = translateTo.getContext().getHeatSharedResourcesByParam() .get(attachedResource.getEntityId()); if (Objects.nonNull(shareResource) && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) { if (!StringUtils.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(), shareResource.getHeatResource().getType())) { logger.warn("Volume attachment used from nested resource " + translateTo.getResourceId() + " is pointing to incorrect resource type(" + shareResource.getHeatResource().getType() + ") for relation through the parameter '" + paramName + "." + " The connection to the volume is ignored. " + "Supported types are: " + HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()); return; } node = shareResource.getTranslatedId(); createRequirementAssignment(entry, node, substitutionNodeTemplate); } else if (Objects.isNull(shareResource)) { List<FileData> allFilesData = translateTo.getContext().getManifest().getContent().getData(); Optional<FileData> fileData = HeatToToscaUtil.getFileData(translateTo.getHeatFileName(), allFilesData); if (fileData.isPresent()) { Optional<ResourceFileDataAndIDs> fileDataContainingResource = new VolumeTranslationHelper( logger).getFileDataContainingVolume(fileData.get().getData(), (String) attachedResource.getEntityId(), translateTo, FileData.Type.HEAT_VOL); if (fileDataContainingResource.isPresent()) { createRequirementAssignment(entry, fileDataContainingResource.get().getTranslatedResourceId(), substitutionNodeTemplate); } } } } }