Search in sources :

Example 6 with FileProvenanceElement

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;
}
Also used : ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) RecoveringManifestParser(org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser) ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) ArrayList(java.util.ArrayList) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement)

Example 7 with FileProvenanceElement

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());
        }
    });
}
Also used : FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

FileProvenanceElement (org.eclipse.winery.accountability.model.FileProvenanceElement)7 ModelProvenanceElement (org.eclipse.winery.accountability.model.ModelProvenanceElement)3 AuthorizationInfo (org.eclipse.winery.accountability.model.authorization.AuthorizationInfo)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ManifestContents (org.eclipse.virgo.util.parser.manifest.ManifestContents)2 RecoveringManifestParser (org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 Objects (java.util.Objects)1 ExecutionException (java.util.concurrent.ExecutionException)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 QueryParam (javax.ws.rs.QueryParam)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MediaType (javax.ws.rs.core.MediaType)1