Search in sources :

Example 81 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class Moderator method updateAttachments.

protected Set<Attachment> updateAttachments(Set<Attachment> attachments, Set<Attachment> attachmentAdditions, Set<Attachment> attachmentDeletions) {
    if (attachments == null) {
        attachments = new HashSet<>();
    }
    Map<String, Attachment> attachmentMap = Maps.uniqueIndex(attachments, Attachment::getAttachmentContentId);
    if (attachmentAdditions != null) {
        for (Attachment update : attachmentAdditions) {
            String id = update.getAttachmentContentId();
            if (attachmentMap.containsKey(id)) {
                Attachment actual = attachmentMap.get(id);
                for (Attachment._Fields field : Attachment._Fields.values()) {
                    if (update.isSet(field)) {
                        actual.setFieldValue(field, update.getFieldValue(field));
                    }
                }
            } else {
                attachments.add(update);
            }
        }
    }
    Map<String, Attachment> additionsMap = attachmentAdditions != null ? Maps.uniqueIndex(attachmentAdditions, Attachment::getAttachmentContentId) : new HashMap<>();
    if (attachmentDeletions != null) {
        for (Attachment delete : attachmentDeletions) {
            if (!additionsMap.containsKey(delete.getAttachmentContentId())) {
                attachments.remove(delete);
            }
        }
    }
    return attachments;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Example 82 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class PortletUtilsTest method setAttachmentTypes.

protected static void setAttachmentTypes(PortletRequest request, AttachmentType... types) {
    List<String> stringTypes = Lists.newArrayList();
    for (AttachmentType type : types) {
        stringTypes.add("" + type.getValue());
    }
    Mockito.when(request.getParameterValues(Release._Fields.ATTACHMENTS.toString() + Attachment._Fields.ATTACHMENT_TYPE.toString())).thenReturn(stringTypes.toArray(new String[] {}));
}
Also used : AttachmentType(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType)

Example 83 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class ComponentImportUtils method removeAutogeneratedAttachments.

private static HashSet<Attachment> removeAutogeneratedAttachments(AttachmentService.Iface attachmentClient, /*read value*/
Attachment attachment, /*read value*/
Release release) throws /*return value*/
TException {
    final HashSet<Attachment> attachmentsToRemove = new HashSet<>();
    if (release.isSetAttachments()) {
        final AttachmentContent attachmentContent = attachmentClient.getAttachmentContent(attachment.getAttachmentContentId());
        final Set<Attachment> attachments = release.getAttachments();
        if (attachmentContent.isSetRemoteUrl()) {
            for (Attachment existentAttachment : attachments) {
                final AttachmentContent existentAttachmentContent = attachmentClient.getAttachmentContent(existentAttachment.getAttachmentContentId());
                if (existentAttachmentContent.isSetRemoteUrl()) {
                    if (existentAttachmentContent.getRemoteUrl().equals(attachmentContent.getRemoteUrl())) {
                        attachmentsToRemove.add(existentAttachment);
                    }
                }
            }
            // This changes the release and this is actually used.
            attachments.removeAll(attachmentsToRemove);
        }
    }
    return attachmentsToRemove;
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Example 84 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class ComponentImportUtils method writeToDatabase.

public static RequestSummary writeToDatabase(Iterable<ComponentCSVRecord> compCSVRecords, ComponentService.Iface componentClient, VendorService.Iface vendorClient, AttachmentService.Iface attachmentClient, User user) throws TException {
    Map<String, String> vendorNameToVendorId = getVendorNameToId(compCSVRecords, vendorClient);
    log.debug(format("Read vendors: (%d) %s ", vendorNameToVendorId.size(), vendorNameToVendorId));
    final RequestSummary componentRequestSummary = updateComponents(compCSVRecords, componentClient, user);
    Map<String, String> componentNameToId = new HashMap<>();
    final ArrayList<Release> releases = new ArrayList<>();
    for (Component component : componentClient.getComponentDetailedSummaryForExport()) {
        componentNameToId.put(component.getName(), component.getId());
        final List<Release> componentReleases = component.getReleases();
        if (componentReleases != null && componentReleases.size() > 0)
            releases.addAll(componentReleases);
    }
    Set<String> knownReleaseIdentifiers = Sets.newHashSet(getReleaseIdentifiers(releases));
    List<ComponentCSVRecord> relevantCSVRecords = new ArrayList<>();
    final HashMap<String, List<String>> releaseIdentifierToDownloadURL = new HashMap<>();
    List<AttachmentContent> attachmentContentsToUpdate = new ArrayList<>();
    filterRelevantCSVRecordsAndGetAttachmentContents(compCSVRecords, componentNameToId, knownReleaseIdentifiers, relevantCSVRecords, releaseIdentifierToDownloadURL, attachmentContentsToUpdate);
    attachmentContentsToUpdate = attachmentClient.makeAttachmentContents(attachmentContentsToUpdate);
    final ImmutableMap<String, AttachmentContent> URLtoAttachment = Maps.uniqueIndex(attachmentContentsToUpdate, new Function<AttachmentContent, String>() {

        @Override
        public String apply(AttachmentContent input) {
            return input.getRemoteUrl();
        }
    });
    Set<Release> releasesToUpdate = new HashSet<>();
    // I do not need so many checks here because I only iterate over the relevant CSV records
    for (ComponentCSVRecord componentCSVRecord : relevantCSVRecords) {
        String releaseIdentifier = componentCSVRecord.getReleaseIdentifier();
        String vendorName = componentCSVRecord.getVendorName();
        String vendorId = vendorNameToVendorId.get(vendorName);
        String componentId = componentNameToId.get(componentCSVRecord.getComponentName());
        List<AttachmentContent> attachmentContents = getAttachmentContents(releaseIdentifierToDownloadURL, URLtoAttachment, releaseIdentifier);
        Release releaseToAdd = componentCSVRecord.getRelease(vendorId, componentId, attachmentContents);
        knownReleaseIdentifiers.add(releaseIdentifier);
        if (releaseToAdd != null) {
            releasesToUpdate.add(releaseToAdd);
        }
    }
    final RequestSummary releaseRequestSummary = componentClient.updateReleases(releasesToUpdate, user);
    return CommonUtils.addRequestSummaries(componentRequestSummary, "component", releaseRequestSummary, "release");
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Component(org.eclipse.sw360.datahandler.thrift.components.Component) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 85 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class ComponentAttachmentCSVRecordBuilderTest method testFillRelease.

@Test
public void testFillRelease() throws Exception {
    final String releaseName = "myRelease";
    final String releaseVersion = "1.862b";
    final Release release = new Release();
    release.setName(releaseName).setVersion(releaseVersion);
    final ComponentAttachmentCSVRecordBuilder componentAttachmentCSVRecordBuilder = new ComponentAttachmentCSVRecordBuilder();
    componentAttachmentCSVRecordBuilder.fill(release);
    final ComponentAttachmentCSVRecord filledRecord = componentAttachmentCSVRecordBuilder.build();
    assertThat(filledRecord.getReleaseIdentifier(), is(SW360Utils.getVersionedName(releaseName, releaseVersion)));
}
Also used : Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Aggregations

Release (org.eclipse.sw360.datahandler.thrift.components.Release)93 User (org.eclipse.sw360.datahandler.thrift.users.User)42 TException (org.apache.thrift.TException)38 Test (org.junit.Test)23 Component (org.eclipse.sw360.datahandler.thrift.components.Component)20 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)20 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)17 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)13 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)13 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)12 FieldMetaData (org.apache.thrift.meta_data.FieldMetaData)11 FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)11 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)10 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)9 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)7 Before (org.junit.Before)7 Collectors (java.util.stream.Collectors)6 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)6 FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)6 IOException (java.io.IOException)5