Search in sources :

Example 86 with Release._Fields

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

the class ComponentImportUtilsTest method assertExpectedComponentsInDb.

private void assertExpectedComponentsInDb() throws TException {
    List<Component> importedComponents = componentClient.getComponentSummary(user);
    List<Release> importedReleases = componentClient.getReleaseSummary(user);
    // see the test file
    assertThat(importedComponents, hasSize(7));
    // see the test file
    assertThat(importedReleases, hasSize(8));
    sortByField(importedComponents, Component._Fields.NAME);
    sortByField(importedReleases, Release._Fields.VERSION);
    sortByField(importedReleases, Release._Fields.NAME);
    Component component = importedComponents.get(0);
    assertThat(component.getName(), is("7-Zip"));
    component = componentClient.getComponentById(component.getId(), user);
    assertThat(component.getName(), is("7-Zip"));
    assertThat(component.getHomepage(), is("http://commons.apache.org/proper/commons-exec"));
    assertThat(component.getVendorNames(), is(emptyOrNullCollectionOf(String.class)));
    assertThat(component.getAttachments(), is(emptyOrNullCollectionOf(Attachment.class)));
    assertThat(component.getCreatedBy(), equalTo(user.getEmail()));
    assertThat(component.getReleases(), is(not(nullValue())));
    assertThat(getReleaseIds(component.getReleases()), containsInAnyOrder(importedReleases.get(0).getId(), importedReleases.get(1).getId()));
    final Release release = importedReleases.get(4);
    assertThat(release.getVersion(), is("1.2.11"));
    // This release has an download url so the import creates an attachmen
    final Set<Attachment> attachments = release.getAttachments();
    assertThat(attachments.size(), is(1));
    final Attachment theAttachment = getFirst(attachments);
    final String attachmentContentId = theAttachment.getAttachmentContentId();
    final AttachmentContent attachmentContent = attachmentClient.getAttachmentContent(attachmentContentId);
    assertThat(attachmentContent.isOnlyRemote(), is(true));
    assertThat(attachmentContent.getRemoteUrl(), is(REMOTE_URL));
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 87 with Release._Fields

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

the class ReleaseClearingStateSummaryComputer method computeReleaseClearingStateSummary.

public static ReleaseClearingStateSummary computeReleaseClearingStateSummary(List<Release> releases, String clearingTeam) {
    ReleaseClearingStateSummary summary = new ReleaseClearingStateSummary(0, 0, 0, 0, 0);
    if (releases == null) {
        return summary;
    }
    for (Release release : releases) {
        Map<String, FossologyStatus> fossologyStatuses = nullToEmptyMap(release.getClearingTeamToFossologyStatus());
        ViewedState globalState = getGlobalState(release.getClearingState());
        ViewedState myTeamState = getStateOfFossology(fossologyStatuses.get(clearingTeam));
        ViewedState otherTeamState = getBestStateOfFossologyForOtherTeams(clearingTeam, fossologyStatuses);
        addReleaseWithStates(summary, globalState, myTeamState, otherTeamState);
    }
    return summary;
}
Also used : FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Release(org.eclipse.sw360.datahandler.thrift.components.Release) ReleaseClearingStateSummary(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStateSummary)

Example 88 with Release._Fields

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

the class ProjectHelper method makeRowsWithReleases.

private SubTable makeRowsWithReleases(Project project) throws SW360Exception {
    List<Release> releases = getReleases(project);
    SubTable table = new SubTable();
    if (releases.size() > 0) {
        for (Release release : releases) {
            List<String> currentRow = makeRowForProject(project);
            currentRow.addAll(releaseHelper.makeRows(release).elements.get(0));
            table.addRow(currentRow);
        }
    } else {
        List<String> projectRowWithEmptyReleaseFields = makeRowForProject(project);
        for (int i = 0; i < releaseHelper.getColumns(); i++) {
            projectRowWithEmptyReleaseFields.add("");
        }
        table.addRow(projectRowWithEmptyReleaseFields);
    }
    return table;
}
Also used : SW360Utils.fieldValueAsString(org.eclipse.sw360.datahandler.common.SW360Utils.fieldValueAsString) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 89 with Release._Fields

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

the class ReleaseHelper method addFieldValueToRow.

private void addFieldValueToRow(List<String> row, Release._Fields field, Release release) throws SW360Exception {
    switch(field) {
        case COMPONENT_ID:
            // first, add data for given field
            row.add(release.getComponentId());
            // second, add joined data, remark that headers have already been added
            // accordingly
            // add component type in every case
            Component component = this.preloadedComponents.get(release.componentId);
            if (component == null) {
                // maybe cache was not initialized properly, so try to load manually
                try {
                    component = cClient.getComponentById(release.getComponentId(), user);
                } catch (TException e) {
                    log.warn("No component found for id " + release.getComponentId() + " which is set in release with id " + release.getId(), e);
                    component = null;
                }
            }
            // check again and add value
            if (component == null) {
                row.add("");
            } else {
                row.add(ThriftEnumUtils.enumToString(component.getComponentType()));
            }
            // and project origin only if wanted
            if (addAdditionalData()) {
                if (releaseClearingStatusDataByRelease.containsKey(release)) {
                    row.add(releaseClearingStatusDataByRelease.get(release).getProjectNames());
                } else {
                    row.add("");
                }
            }
            break;
        case VENDOR:
            addVendorToRow(release.getVendor(), row);
            break;
        case COTS_DETAILS:
            addCotsDetailsToRow(release.getCotsDetails(), row);
            break;
        case CLEARING_INFORMATION:
            addClearingInformationToRow(release.getClearingInformation(), row);
            break;
        case ECC_INFORMATION:
            addEccInformationToRow(release.getEccInformation(), row);
            break;
        case RELEASE_ID_TO_RELATIONSHIP:
            addReleaseIdToRelationShipToRow(release.getReleaseIdToRelationship(), row);
            break;
        case ATTACHMENTS:
            String size = Integer.toString(release.isSetAttachments() ? release.getAttachments().size() : 0);
            row.add(size);
            break;
        default:
            Object fieldValue = release.getFieldValue(field);
            row.add(fieldValueAsString(fieldValue));
    }
}
Also used : TException(org.apache.thrift.TException) SW360Utils.fieldValueAsString(org.eclipse.sw360.datahandler.common.SW360Utils.fieldValueAsString)

Example 90 with Release._Fields

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

the class AttachmentController method createHalAttachment.

private HalResource<Attachment> createHalAttachment(Attachment sw360Attachment, Release sw360Release, User sw360User) {
    HalResource<Attachment> halAttachment = new HalResource<>(sw360Attachment);
    String componentUUID = sw360Attachment.getAttachmentContentId();
    Link releaseLink = linkTo(AttachmentController.class).slash("api/releases/" + sw360Release.getId()).withRel("release");
    halAttachment.add(releaseLink);
    restControllerHelper.addEmbeddedRelease(halAttachment, sw360Release);
    restControllerHelper.addEmbeddedUser(halAttachment, sw360User, "createdBy");
    return halAttachment;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) Link(org.springframework.hateoas.Link)

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