protected ProvenanceVerification verifyFileInManifest(ModelProvenanceElement element, String fileId, String checksum) throws SerializationException { // 1. parse element.state as ManifestContent ManifestContents manifestContents = new RecoveringManifestParser() .parse(element.getFingerprint()); if (manifestContents.getSectionNames().contains(fileId)) { String storedHash = manifestContents.getAttributesForSection(fileId).get(TOSCAMetaFileAttributes.HASH); if (Objects.isNull(storedHash)) { return NO_HASH_AVAILABLE; } else if (storedHash.equals(checksum)) { // 2.1 if section == fileId and hash == checksum -> file verified return VERIFIED; } else { return INVALID; } } return ID_NOT_FOUND; }
public static ManifestContents getManifest(Reader reader) { ManifestParser parser = new RecoveringManifestParser(); try { ManifestContents manifest = parser.parse(reader); if (parser.foundProblems()) { for (ManifestProblem problem : parser.getProblems()) { System.err.println(problem.toStringWithContext()); System.err.println(); } throw new RuntimeException("There was a problem with the manifest"); } return manifest; } catch (IOException e) { throw new RuntimeException(e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { // Nothing to do } } } }
parser = new RecoveringManifestParser(); reader = new FileReader(toscaMetaFile.toFile()); TOSCAMetaFileParser.LOGGER.debug("Parsing TOSCA meta file \"{}\"...", toscaMetaFile.getFileName().toString());
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); } }
for (ModelProvenanceElement modelProvenanceElement : historyElements) { if (Objects.nonNull(modelProvenanceElement.getFingerprint())) { ManifestContents manifestContents = new RecoveringManifestParser() .parse(modelProvenanceElement.getFingerprint());