Search in sources :

Example 66 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.

the class CLIParserTest method testIsApplicableToFailsOnMalformedXML.

@Test
public void testIsApplicableToFailsOnMalformedXML() throws Exception {
    AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
    when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader("this is not an xml file")));
    assertFalse(parser.isApplicableTo(attachment, new User(), new Project()));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) User(org.eclipse.sw360.datahandler.thrift.users.User) StringReader(java.io.StringReader) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Test(org.junit.Test)

Example 67 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project 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 68 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project 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 69 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.

the class CommonUtilsTest method testIsMapFieldMapOfStringSets_NoSet.

@Test
public void testIsMapFieldMapOfStringSets_NoSet() throws Exception {
    Map<String, String> externalIds = new HashMap<>();
    externalIds.put("ext1", "id1");
    externalIds.put("ext2", "id2");
    Project project = new Project().setName("pname").setExternalIds(externalIds);
    boolean b = isMapFieldMapOfStringSets(Project._Fields.EXTERNAL_IDS, project, project, project, Logger.getLogger(CommonUtilsTest.class));
    assertThat(b, is(false));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 70 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.

the class CommonUtilsTest method testIsMapFieldMapOfStringSets_EmptyMaps.

@Test
public void testIsMapFieldMapOfStringSets_EmptyMaps() throws Exception {
    Map<String, Set<String>> roleMap = new HashMap<>();
    Project project = new Project().setName("pname").setRoles(roleMap);
    boolean b = isMapFieldMapOfStringSets(Project._Fields.ROLES, project, project, project, Logger.getLogger(CommonUtilsTest.class));
    assertThat(b, is(false));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Project (org.eclipse.sw360.datahandler.thrift.projects.Project)87 User (org.eclipse.sw360.datahandler.thrift.users.User)46 Test (org.junit.Test)42 TException (org.apache.thrift.TException)27 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)16 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)12 Release (org.eclipse.sw360.datahandler.thrift.components.Release)12 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)10 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)7 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)6 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 HashSet (java.util.HashSet)5 ResponseEntity (org.springframework.http.ResponseEntity)5