use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentSummary method summary.
@Override
protected Component summary(SummaryType type, Component document) {
Component copy = new Component();
if (type == SummaryType.EXPORT_SUMMARY) {
List<Release> releases = releaseRepository.getReleasesFromComponentId(document.getId());
return makeExportSummary(document, releases);
} else if (type == SummaryType.DETAILED_EXPORT_SUMMARY) {
List<Release> releases = releaseRepository.getReleasesFromComponentId(document.getId());
final Map<String, Vendor> vendorsById = ThriftUtils.getIdMap(vendorRepository.getAll());
for (Release release : releases) {
if (!release.isSetVendor() && release.isSetVendorId()) {
release.setVendor(vendorsById.get(release.getVendorId()));
}
}
return makeDetailedExportSummary(document, releases);
} else if (type == SummaryType.HOME) {
copyField(document, copy, Component._Fields.ID);
copyField(document, copy, Component._Fields.DESCRIPTION);
}
copyField(document, copy, Component._Fields.ID);
copyField(document, copy, Component._Fields.NAME);
copyField(document, copy, Component._Fields.VENDOR_NAMES);
copyField(document, copy, Component._Fields.COMPONENT_TYPE);
if (type == SummaryType.SUMMARY) {
for (Component._Fields field : Component.metaDataMap.keySet()) {
copyField(document, copy, field);
}
}
return copy;
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ProjectDatabaseHandlerTest method setUp.
@Before
public void setUp() throws Exception {
assertTestString(dbName);
assertTestString(attachmentsDbName);
List<Project> projects = new ArrayList<>();
Project p1 = new Project().setId("P1").setName("Project1").setBusinessUnit("AB CD EF").setCreatedBy("user1").setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r3", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r4", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r5", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r6", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build());
projects.add(p1);
Project p2 = new Project().setId("P2").setName("Project2").setBusinessUnit("AB CD FE").setCreatedBy("user2").setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r3", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build());
projects.add(p2);
projects.get(1).addToContributors("user1");
projects.add(new Project().setId("P3").setName("Project3").setBusinessUnit("AB CD EF").setCreatedBy("user3"));
Project p4 = new Project().setId("P4").setName("Project4").setBusinessUnit("AB CD EF").setCreatedBy("user1").setVisbility(Visibility.PRIVATE).setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build()).setLinkedProjects(ImmutableMap.<String, ProjectRelationship>builder().put("P5", ProjectRelationship.CONTAINED).build());
projects.add(p4);
projects.add(new Project().setId("P5").setName("Project5").setBusinessUnit("AB CD EF").setCreatedBy("user1"));
List<Release> releases = new ArrayList<>();
releases.add(new Release().setId("r1").setComponentId("c1"));
releases.add(new Release().setId("r2").setComponentId("c1"));
releases.add(new Release().setId("r3").setComponentId("c1"));
releases.add(new Release().setId("r4").setComponentId("c1"));
releases.add(new Release().setId("r5").setComponentId("c1"));
releases.add(new Release().setId("r6").setComponentId("c1"));
// Create the database
TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
// Prepare the database
DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
for (Project project : projects) {
databaseConnector.add(project);
}
for (Release r : releases) {
databaseConnector.add(r);
}
databaseConnector.add(new Component("comp1").setId("c1"));
componentHandler = new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName);
handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentDbName, moderator, componentHandler);
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testDuplicateComponentNotAdded.
@Test
public void testDuplicateComponentNotAdded() throws Exception {
String originalComponentId = "C3";
final Component tmp = handler.getComponent(originalComponentId, user1);
tmp.unsetId();
tmp.unsetRevision();
String newComponentId = handler.addComponent(tmp, email1).getId();
final Map<String, List<String>> duplicateComponents = handler.getDuplicateComponents();
assertThat(duplicateComponents.size(), is(0));
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testDontDeleteUsedComponent.
@Test
public void testDontDeleteUsedComponent() throws Exception {
final Release r1A = handler.getRelease("R1A", user1);
r1A.setReleaseIdToRelationship(ImmutableMap.of("R2A", ReleaseRelationship.CONTAINED));
handler.updateRelease(r1A, user1, ThriftUtils.IMMUTABLE_OF_RELEASE);
RequestStatus status = handler.deleteComponent("C2", user1);
assertEquals(RequestStatus.IN_USE, status);
List<Component> componentSummary = handler.getComponentSummary(user1);
assertEquals(3, componentSummary.size());
assertTrue("Component not deleted", componentsContain(componentSummary, "C2"));
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testUpdateComponentSentToModeration.
@Test
public void testUpdateComponentSentToModeration() throws Exception {
// Make some changes in the component
Component component = components.get(0);
String expected = component.getName();
component.setName("UPDATE");
when(moderator.updateComponent(component, user2)).thenReturn(RequestStatus.SENT_TO_MODERATOR);
RequestStatus status = handler.updateComponent(component, user2);
Component actual = handler.getComponent("C1", user1);
assertEquals(RequestStatus.SENT_TO_MODERATOR, status);
assertEquals(component.getId(), actual.getId());
assertEquals(expected, actual.getName());
verify(moderator).updateComponent(component, user2);
}
Aggregations