List of usage examples for java.util Optional get
public T get()
From source file:com.netflix.spinnaker.orca.clouddriver.tasks.pipeline.MigratePipelineClustersTask.java
@Override public TaskResult execute(Stage stage) { Map<String, Object> context = stage.getContext(); Optional<Map<String, Object>> pipelineMatch = getPipeline(context); if (!pipelineMatch.isPresent()) { return pipelineNotFound(context); }/*from w ww. ja v a 2 s. co m*/ List<Map> sources = getSources(pipelineMatch.get()); List<Map<String, Map>> operations = generateKatoOperation(context, sources); TaskId taskId = katoService.requestOperations(getCloudProvider(stage), operations).toBlocking().first(); Map<String, Object> outputs = new HashMap<>(); outputs.put("notification.type", "migratepipelineclusters"); outputs.put("kato.last.task.id", taskId); outputs.put("source.pipeline", pipelineMatch.get()); return new DefaultTaskResult(ExecutionStatus.SUCCEEDED, outputs); }
From source file:io.syndesis.rest.v1.handler.integration.IntegrationHandler.java
@Override public Integration get(String id) { Integration integration = Getter.super.get(id); if (Status.Deleted.equals(integration.getCurrentStatus().get()) || Status.Deleted.equals(integration.getDesiredStatus().get())) { //Not sure if we need to do that for both current and desired status, //but If we don't do include the desired state, IntegrationITCase is not going to pass anytime soon. Why? //Cause that test, is using NoopHandlerProvider, so that means no controllers. throw new EntityNotFoundException( String.format("Integration %s has been deleted", integration.getId())); }// w w w . j a v a 2 s . c o m //fudging the timesUsed for now Optional<Status> currentStatus = integration.getCurrentStatus(); if (currentStatus.isPresent() && currentStatus.get() == Integration.Status.Activated) { return new Integration.Builder().createFrom(integration) .timesUsed(BigInteger.valueOf(new Date().getTime() / 1000000)).build(); } return integration; }
From source file:com.cybernostics.jsp2thymeleaf.api.elements.CopyElementConverter.java
@Override public List<Content> process(JSPParser.JspElementContext node, JSPElementNodeConverter context) { Optional<Element> maybeElement = createElement(node, context); if (maybeElement.isPresent()) { Element element = maybeElement.get(); element.removeNamespaceDeclaration(XMLNS); element.addContent(getNewChildContent(node, context)); addAttributes(element, node, context); return Stream.concat(Stream.of(element), getNewAppendedContent(node, context).stream()) .collect(toList());/*from www . ja v a2 s. c o m*/ } return EMPTY_LIST; }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.op.artifact.KubernetesCleanupArtifactsOperation.java
private List<Artifact> artifactsToDelete(KubernetesManifest manifest) { KubernetesManifestStrategy strategy = KubernetesManifestAnnotater.getStrategy(manifest); if (strategy.getMaxVersionHistory() == null) { return new ArrayList<>(); }// w w w . j a va 2s . c o m int maxVersionHistory = strategy.getMaxVersionHistory(); Optional<Artifact> optional = KubernetesManifestAnnotater.getArtifact(manifest); if (!optional.isPresent()) { return new ArrayList<>(); } Artifact artifact = optional.get(); List<Artifact> artifacts = artifactProvider .getArtifacts(artifact.getType(), artifact.getName(), artifact.getLocation()).stream() .filter(a -> a.getMetadata() != null && accountName.equals(a.getMetadata().get("account"))) .collect(Collectors.toList()); if (maxVersionHistory >= artifacts.size()) { return new ArrayList<>(); } else { return artifacts.subList(0, artifacts.size() - maxVersionHistory); } }
From source file:org.obiba.mica.search.aggregations.TaxonomyAggregationMetaDataProvider.java
private Map<String, LocalizedMetaData> getAllLocalizedMetadata(String aggregation) { Optional<Vocabulary> vocabulary = getVocabulary(aggregation); if (vocabulary.isPresent()) { Map<String, LocalizedMetaData> r = Maps.newHashMap(); for (Term t : vocabulary.get().getTerms()) { LocalizedString title = new LocalizedString(); title.putAll(t.getTitle());/*from w ww . j a v a2 s.com*/ LocalizedString description = new LocalizedString(); description.putAll(t.getDescription()); String className = t.getAttributeValue("className"); if (Strings.isNullOrEmpty(className)) { className = t.getClass().getSimpleName(); } if (!r.containsKey(t.getName())) { r.put(t.getName(), new LocalizedMetaData(title, description, className)); } } return r; } return null; }
From source file:org.ow2.proactive.connector.iaas.cloud.provider.vmware.VMWareProviderVirtualMachineUtil.java
public Optional<Folder> searchVMFolderFromVMName(String name, Folder rootFolder) { ManagedEntity vmFolder = null;/*from w ww .j av a 2 s . com*/ Optional<VirtualMachine> vm = searchVirtualMachineByName(name, rootFolder); if (vm.isPresent()) { ManagedEntity current = vm.get().getParent(); while (current != null && !(current instanceof Folder)) { current = current.getParent(); } vmFolder = current; } return Optional.ofNullable((Folder) vmFolder); }
From source file:me.dags.creativeblock.blockpack.FolderBlockPack.java
@Override public List<BlockDefinition> getDefinitions() { List<BlockDefinition> definitions = new ArrayList<>(); final File definitionsDir = FileUtil.getDir(this.getSource(), "assets", creativeBlock.domain(), "definitions"); final File texturesDir = FileUtil.getDir(this.getSource(), "assets", creativeBlock.domain(), "textures", "blocks"); Iterator<File> defIterator = FileUtils.iterateFilesAndDirs(definitionsDir, definitionsFilter(), TrueFileFilter.INSTANCE);/*from w ww. j a v a 2s .c o m*/ while (defIterator.hasNext()) { File file = defIterator.next(); Optional<DefinitionSerializable> optional = JsonUtil.deserialize(file, DefinitionSerializable.class); if (optional.isPresent()) { DefinitionSerializable jsonDefinition = optional.get(); jsonDefinition.tabId = getTabName(definitionsDir, file); BlockDefinition definition = BlockDefinition.from(optional.get()); definitions.add(definition); } } return definitions; }
From source file:it.polimi.diceH2020.launcher.controller.FilesController.java
@RequestMapping(value = "/upload", method = RequestMethod.POST) public String multipleSave(@RequestParam("file[]") MultipartFile[] files, @RequestParam("scenario") String useCase, Model model, RedirectAttributes redirectAttrs) { boolean singleInputData = false; Scenarios scenario = Scenarios.valueOf(useCase); ArrayList<String> tmpValues = new ArrayList<>(); redirectAttrs.addAttribute("scenario", scenario); model.addAttribute("scenario", scenario); if (files == null || files.length == 0) { model.addAttribute("message", "Wrong files!"); return "launchSimulation_FileUpload"; }/*from w ww . ja v a2 s . co m*/ if (hasDuplicate( Arrays.stream(files).map(MultipartFile::getOriginalFilename).collect(Collectors.toList()))) { model.addAttribute("message", "Duplicated files!"); return "launchSimulation_FileUpload"; } for (int i = 0; i < files.length; i++) { String fileName = files[i].getOriginalFilename() .substring(files[i].getOriginalFilename().lastIndexOf("/") + 1); File f = saveFile(files[i], fileName); if (f == null) return "error"; if (fileName.contains(".json")) { Optional<InstanceDataMultiProvider> idmp = validator.readInstanceDataMultiProvider(f.toPath()); if (idmp.isPresent()) { if (idmp.get().validate()) { redirectAttrs.addAttribute("instanceDataMultiProvider", f.toPath().toString()); continue; } else { model.addAttribute("message", idmp.get().getValidationError()); return "launchSimulation_FileUpload"; } } model.addAttribute("message", "You have submitted an invalid json!"); return "launchSimulation_FileUpload"; } else { if (fileName.contains(".txt")) { tmpValues.add(f.toPath().toString()); } } } redirectAttrs.addAttribute("pathList", tmpValues); if (singleInputData) return "redirect:/launch/simulationSetupSingleInputData"; return "redirect:/launch/simulationSetup"; }
From source file:org.openmhealth.shim.googlefit.mapper.GoogleFitDataPointMapper.java
/** * Maps a JSON response from the Google Fit API containing a JSON array of data points to a list of {@link * DataPoint} objects of the appropriate measure type. Splits individual nodes based on the name of the list node, * "point," and then iteratively maps the nodes in the list. * * @param responseNodes the response body from a Google Fit endpoint, contained in a list of a single JSON node * @return a list of DataPoint objects of type T with the appropriate values mapped from the input JSON; because * these JSON objects are contained within an array in the input response, each object in that JSON array will map * to an item in the returned list//ww w . j a va 2s. c o m */ public List<DataPoint<T>> asDataPoints(List<JsonNode> responseNodes) { checkNotNull(responseNodes); checkArgument(responseNodes.size() == 1, "Only one response should be input to the mapper"); List<DataPoint<T>> dataPoints = Lists.newArrayList(); Optional<JsonNode> listNodes = asOptionalNode(responseNodes.get(0), getListNodeName()); if (listNodes.isPresent()) { for (JsonNode listNode : listNodes.get()) { asDataPoint(listNode).ifPresent(dataPoints::add); } } return dataPoints; }
From source file:com.github.horrorho.inflatabledonkey.chunk.store.disk.DiskChunkStoreTest.java
@Ignore @Test/*from w w w . j a v a 2s . c o m*/ @Parameters public void test(byte[] data) throws IOException { Supplier<Digest> digests = SHA1Digest::new; DiskChunkStore store = new DiskChunkStore(digests, ChunkDigests::test, CACHE, TEMP); byte[] checksum = digest(digests, data); Optional<OutputStream> chunkOutputStream = store.outputStream(checksum); assertTrue("OutputStream present", chunkOutputStream.isPresent()); try (OutputStream os = chunkOutputStream.get()) { os.write(data); } Optional<Chunk> chunkData = store.chunk(checksum); assertTrue("Chunk present", chunkData.isPresent()); Chunk chunk = chunkData.get(); assertArrayEquals("checksum match", checksum, chunk.checksum()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (InputStream is = chunk.inputStream().orElseThrow(() -> new IllegalStateException("chunk deleted"))) { IOUtils.copy(is, baos); } assertArrayEquals("data match", data, baos.toByteArray()); Optional<OutputStream> duplicateOutputStream = store.outputStream(checksum); assertFalse("duplicate OutputStream not present", duplicateOutputStream.isPresent()); boolean isDeleted = store.delete(checksum); assertTrue("was deleted", isDeleted); Optional<Chunk> deleted = store.chunk(checksum); assertFalse(deleted.isPresent()); assertFalse("temp folder is empty", Files.list(TEMP).findFirst().isPresent()); }