use of org.eclipse.winery.accountability.model.FileProvenanceElement in project winery by eclipse.
the class AccountabilityManagerImpl method getHistoryOfSingleFile.
protected List<FileProvenanceElement> getHistoryOfSingleFile(List<ModelProvenanceElement> historyElements, String fileId, AuthorizationInfo authorizationInfo) {
List<FileProvenanceElement> history = new ArrayList<>();
if (Objects.nonNull(historyElements) && historyElements.size() > 0) {
for (ModelProvenanceElement modelProvenanceElement : historyElements) {
if (Objects.nonNull(modelProvenanceElement.getFingerprint())) {
ManifestContents manifestContents = new RecoveringManifestParser().parse(modelProvenanceElement.getFingerprint());
for (String name : manifestContents.getSectionNames()) {
if (name.equals(fileId)) {
modelProvenanceElement.setAuthorizedFlag(authorizationInfo);
modelProvenanceElement.setAuthorName(authorizationInfo.getRealWorldIdentity(modelProvenanceElement.getAuthorAddress()).orElseGet(String::new));
FileProvenanceElement currentFile = new FileProvenanceElement(modelProvenanceElement);
currentFile.setAddressInImmutableStorage(manifestContents.getAttributesForSection(name).get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS));
currentFile.setFileHash(TOSCAMetaFileAttributes.HASH + "-" + manifestContents.getAttributesForSection(name).get(TOSCAMetaFileAttributes.HASH));
currentFile.setFileName(fileId);
history.add(currentFile);
break;
}
}
}
}
}
if (history.size() > 0)
return history;
return null;
}
use of org.eclipse.winery.accountability.model.FileProvenanceElement in project winery by eclipse.
the class AccountabilityManagerImplTest method getHistoryOfSingleFile.
@ParameterizedTest(name = "{index} => ''{5}''")
@MethodSource("getHistoryOfSingleFileArguments")
public void getHistoryOfSingleFile(List<ModelProvenanceElement> historyElements, String fileId, List<FileProvenanceElement> expectedElements, AuthorizationInfo authorizationInfo, boolean[] isAuthorized, String description) {
List<FileProvenanceElement> actual = provenance.getHistoryOfSingleFile(historyElements, fileId, authorizationInfo);
assumingThat(Objects.nonNull(expectedElements), () -> {
assertNotNull(actual);
assertEquals(expectedElements.size(), actual.size());
for (FileProvenanceElement historyElement : actual) {
assertTrue(expectedElements.indexOf(historyElement) >= 0);
}
});
assumingThat(Objects.nonNull(isAuthorized), () -> {
for (FileProvenanceElement historyElement : actual) {
assertEquals(isAuthorized[actual.indexOf(historyElement)], historyElement.isAuthorized());
}
});
}
Aggregations