use of org.eclipse.sw360.datahandler.thrift.components.Release in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testDontDeleteComponentWithReleaseContained.
@Test
public void testDontDeleteComponentWithReleaseContained() throws Exception {
Component component = new Component().setId("Del").setName("delete").setDescription("d1").setCreatedBy(email1);
Release release = new Release().setId("DelR").setComponentId("Del").setName("delete Release").setVersion("1.0").setCreatedBy(email1).setVendorId("V1").setClearingState(ClearingState.NEW_CLEARING);
handler.addComponent(component, email1);
handler.addRelease(release, email1);
{
Component del = handler.getComponent("Del", user1);
assertThat(del.getName(), is("delete"));
Release delR = handler.getRelease("DelR", user1);
assertThat(delR.getName(), is("delete Release"));
}
RequestStatus status = handler.deleteComponent("Del", user1);
assertThat(status, is(RequestStatus.IN_USE));
{
Component del = handler.getComponent("Del", user1);
assertThat(del.getName(), is("delete"));
Release delR = handler.getRelease("DelR", user1);
assertThat(delR.getName(), is("delete Release"));
}
}
use of org.eclipse.sw360.datahandler.thrift.components.Release in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testAddReleaseUpdatesProgrammingLanguagesOperatingSystemsAndVendorNames.
@Test
public void testAddReleaseUpdatesProgrammingLanguagesOperatingSystemsAndVendorNames() throws Exception {
String componentId = "C4";
{
Component component = new Component().setId(componentId).setName("component4").setDescription("d4").setCreatedBy(email1);
handler.addComponent(component, email1);
}
{
Component component = handler.getComponent(componentId, user1);
assertTrue("Check that languages are not initialized", component.languages == null);
assertTrue("Check that operating systems are not initialized", component.operatingSystems == null);
assertTrue("Check that vendor names are not initialized", component.vendorNames == null);
}
Set<String> os = new HashSet<>();
os.add("Linux Ubuntu");
os.add("Linux Mint");
Set<String> lang = new HashSet<>();
lang.add("C");
lang.add("C++");
Release release = new Release().setName("REL").setVersion("VER").setOperatingSystems(os).setLanguages(lang).setVendorId("V1");
release.setComponentId(componentId);
String id = handler.addRelease(release, user1.getEmail()).getId();
assertNotNull(id);
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.languages, containsInAnyOrder("C", "C++"));
assertThat(component.operatingSystems, containsInAnyOrder("Linux Ubuntu", "Linux Mint"));
assertThat(component.vendorNames, containsInAnyOrder(vendors.get("V1").getShortname()));
}
Set<String> os2 = new HashSet<>();
os2.add("Linux Debian");
os2.add("Linux Mint");
Set<String> lang2 = new HashSet<>();
lang2.add("C#");
lang2.add("C++");
Release release2 = new Release().setName("REL2").setVersion("VER2").setOperatingSystems(os2).setLanguages(lang2).setVendorId("V2");
release2.setComponentId(componentId);
String id2 = handler.addRelease(release2, user1.getEmail()).getId();
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.languages, containsInAnyOrder("C", "C++", "C#"));
assertThat(component.operatingSystems, containsInAnyOrder("Linux Ubuntu", "Linux Mint", "Linux Debian"));
assertThat(component.vendorNames, containsInAnyOrder(vendors.get("V1").getShortname(), vendors.get("V2").getShortname()));
}
handler.deleteRelease(id, user1);
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.languages, containsInAnyOrder("C++", "C#"));
assertThat(component.operatingSystems, containsInAnyOrder("Linux Mint", "Linux Debian"));
assertThat(component.vendorNames, containsInAnyOrder(vendors.get("V2").getShortname()));
}
handler.deleteRelease(id2, user1);
{
Component component = handler.getComponent(componentId, user1);
assertThat(component.languages, is(empty()));
assertThat(component.operatingSystems, is(empty()));
assertThat(component.vendorNames, is(empty()));
}
}
use of org.eclipse.sw360.datahandler.thrift.components.Release in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testDeleteRelease.
@Test
public void testDeleteRelease() throws Exception {
RequestStatus status = handler.deleteRelease("R1B", user2);
assertEquals(RequestStatus.SUCCESS, status);
List<Release> releaseSummary = handler.getReleaseSummary();
assertEquals(4, releaseSummary.size());
assertFalse("Component deleted", releasesContain(releaseSummary, "R1B"));
// Check deletion in component
Component component = handler.getComponent("C1", user1);
assertEquals(1, component.getReleasesSize());
assertFalse("Release deleted", releasesContain(component.getReleases(), "R1B"));
}
use of org.eclipse.sw360.datahandler.thrift.components.Release in project sw360portal by sw360.
the class ProjectDatabaseHandlerTest method setUp.
@Before
public void setUp() throws Exception {
assertTestString(dbName);
assertTestString(attachmentsDbName);
vendors = new ArrayList<>();
vendors.add(new Vendor().setId("V1").setShortname("vendor").setFullname("vendor").setUrl("http://vendor.example.com"));
releases = new ArrayList<>();
Release release1a = new Release().setId("R1A").setComponentId("C1").setName("component1").setVersion("releaseA").setVendorId("V1");
releases.add(release1a);
Release release1b = new Release().setId("R1B").setComponentId("C1").setName("component1").setVersion("releaseB").setVendorId("V1");
releases.add(release1b);
Release release2a = new Release().setId("R2A").setComponentId("C2").setName("component2").setVersion("releaseA").setVendorId("V1");
releases.add(release2a);
Release release2b = new Release().setId("R2B").setComponentId("C2").setName("component2").setVersion("releaseB").setVendorId("V1");
releases.add(release2b);
components = new ArrayList<>();
Component component1 = new Component().setId("C1").setName("component1").setDescription("d1").setComponentType(ComponentType.OSS);
components.add(component1);
Component component2 = new Component().setId("C2").setName("component2").setDescription("d2").setComponentType(ComponentType.COTS);
components.add(component2);
projects = new ArrayList<>();
Project project1 = new Project().setId("P1").setName("project1").setLinkedProjects(ImmutableMap.of("P2", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
projects.add(project1);
Project project2 = new Project().setId("P2").setName("project2").setLinkedProjects(ImmutableMap.of("P3", ProjectRelationship.REFERRED, "P4", ProjectRelationship.CONTAINED)).setReleaseIdToUsage(ImmutableMap.of("R1A", newDefaultProjectReleaseRelationship(), "R1B", newDefaultProjectReleaseRelationship())).setVisbility(Visibility.EVERYONE);
projects.add(project2);
Project project3 = new Project().setId("P3").setName("project3").setLinkedProjects(ImmutableMap.of("P2", ProjectRelationship.UNKNOWN)).setReleaseIdToUsage(ImmutableMap.of("R2A", newDefaultProjectReleaseRelationship(), "R2B", newDefaultProjectReleaseRelationship())).setVisbility(Visibility.EVERYONE);
projects.add(project3);
Project project4 = new Project().setId("P4").setName("project4").setLinkedProjects(ImmutableMap.of("P1", ProjectRelationship.UNKNOWN)).setVisbility(Visibility.EVERYONE);
projects.add(project4);
Project project5 = new Project().setId("P5").setName("project5").setLinkedProjects(ImmutableMap.of("P6", ProjectRelationship.CONTAINED, "P7", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
projects.add(project5);
Project project6 = new Project().setId("P6").setName("project6").setLinkedProjects(ImmutableMap.of("P7", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
projects.add(project6);
Project project7 = new Project().setId("P7").setName("project7").setVisbility(Visibility.EVERYONE);
projects.add(project7);
// Create the database
TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
// Prepare the database
DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
for (Vendor vendor : vendors) {
databaseConnector.add(vendor);
}
for (Release release : releases) {
databaseConnector.add(release);
}
for (Component component : components) {
databaseConnector.add(component);
}
for (Project project : projects) {
databaseConnector.add(project);
}
ComponentDatabaseHandler componentHandler = new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName);
handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName, moderator, componentHandler);
}
use of org.eclipse.sw360.datahandler.thrift.components.Release in project sw360portal by sw360.
the class ProjectDatabaseHandler method fillClearingStateSummary.
public List<Project> fillClearingStateSummary(List<Project> projects, User user) {
Function<Project, Set<String>> extractReleaseIds = project -> CommonUtils.nullToEmptyMap(project.getReleaseIdToUsage()).keySet();
Set<String> allReleaseIds = projects.stream().map(extractReleaseIds).reduce(Sets.newHashSet(), Sets::union);
if (!allReleaseIds.isEmpty()) {
Map<String, Release> releasesById = ThriftUtils.getIdMap(componentDatabaseHandler.getReleasesForClearingStateSummary(allReleaseIds));
for (Project project : projects) {
final Set<String> releaseIds = extractReleaseIds.apply(project);
List<Release> releases = releaseIds.stream().map(releasesById::get).collect(Collectors.toList());
final ReleaseClearingStateSummary releaseClearingStateSummary = ReleaseClearingStateSummaryComputer.computeReleaseClearingStateSummary(releases, project.getClearingTeam());
project.setReleaseClearingStateSummary(releaseClearingStateSummary);
}
}
return projects;
}
Aggregations