private void fillFilesOfModel(ModelProvenanceElement model) { // 1. parse element.state as ManifestContent RecoveringManifestParser genericParser = new RecoveringManifestParser(); ManifestContents manifestContents = genericParser.parse(model.getFingerprint()); // 2. parse the ManifestContent as a TOSCAMetaFile TOSCAMetaFileParser parser = new TOSCAMetaFileParser(); TOSCAMetaFile toscaMetaFile = parser.parse(manifestContents, genericParser.getProblems().size()); //3. retrieve files from meta file Objects.requireNonNull(toscaMetaFile); List<FileProvenanceElement> result = toscaMetaFile .getFileBlocks() .stream() .map( fileSection -> { FileProvenanceElement fileElement = new FileProvenanceElement(model); fileElement.setFileHash(fileSection.get(TOSCAMetaFileAttributes.HASH)); fileElement.setAddressInImmutableStorage(fileSection.get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS)); fileElement.setFileName(fileSection.get(TOSCAMetaFileAttributes.NAME)); return fileElement; } ) .sorted(Comparator.comparing(FileProvenanceElement::getFileName)) .collect(Collectors.toList()); model.setFiles(result); } }
@Override public CompletableFuture<List<FileProvenanceElement>> getHistory(String processIdentifier, String fileId) { CompletableFuture<AuthorizationInfo> authorizationTree = this.blockchain.getAuthorizationTree(processIdentifier); return this.blockchain .getProvenance(processIdentifier) .thenCombine(authorizationTree, (provenanceElements, authorizationInfo) -> { List<FileProvenanceElement> result; if (authorizationInfo != null) { result = getHistoryOfSingleFile(provenanceElements, fileId, authorizationInfo); } else { LOGGER.info(NO_AUTHORIZATION_DATA); FileProvenanceElement historyElement = new FileProvenanceElement("", 0, NO_AUTHORIZATION_DATA); historyElement.setAuthorized(false); historyElement.setFileName(fileId); result = Collections.singletonList(historyElement); } return result; }); }
manifestContents.getAttributesForSection(name) .get(TOSCAMetaFileAttributes.HASH)); currentFile.setFileName(fileId); history.add(currentFile);