use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testDeleteReleaseNotModerator.
@Test
public void testDeleteReleaseNotModerator() throws Exception {
when(releaseModerator.deleteRelease(any(Release.class), eq(user1))).thenReturn(RequestStatus.SENT_TO_MODERATOR);
RequestStatus status = handler.deleteRelease("R1B", user1);
assertEquals(RequestStatus.SENT_TO_MODERATOR, status);
List<Release> releaseSummary = handler.getReleaseSummary();
assertEquals(5, releaseSummary.size());
assertTrue("Component NOT deleted", releasesContain(releaseSummary, "R1B"));
verify(releaseModerator).deleteRelease(any(Release.class), eq(user1));
}
use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method testUpdateRelease.
@Test
public void testUpdateRelease() throws Exception {
Release expected = releases.get(1);
expected.setName("UPDATED");
RequestStatus status = handler.updateRelease(expected, user2, ThriftUtils.IMMUTABLE_OF_RELEASE);
Release actual = handler.getRelease("R1B", user1);
assertEquals(RequestStatus.SUCCESS, status);
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getName(), actual.getName());
assertEquals(expected.getVersion(), actual.getVersion());
assertEquals(expected.getComponentId(), actual.getComponentId());
assertEquals(email2, actual.getCreatedBy());
// Check releases
assertEquals(1, actual.getSubscribersSize());
assertTrue(actual.getSubscribers().contains(email1));
}
use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.
the class VulnerabilityConnector method addOrUpdateVulnerabilityAndSetId.
public Map<UpdateType, List<Vulnerability>> addOrUpdateVulnerabilityAndSetId(Vulnerability vulnerability, Map<UpdateType, List<Vulnerability>> statusToVulnerabilities) {
Vulnerability dbVulnerability = vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, vulnerability.getExternalId());
if (dbVulnerability != null) {
if (!isMoreRecent(vulnerability, dbVulnerability)) {
statusToVulnerabilities.get(UpdateType.OLD).add(dbVulnerability);
return statusToVulnerabilities;
} else {
dbVulnerability = VulnerabilityMapper.updateFromVulnerability(dbVulnerability, vulnerability);
RequestStatus requestStatus = vulnerabilityDatabaseHandler.update(dbVulnerability);
if (RequestStatus.SUCCESS.equals(requestStatus)) {
statusToVulnerabilities.get(UpdateType.UPDATED).add(dbVulnerability);
return statusToVulnerabilities;
}
}
} else {
RequestStatus requestStatus = vulnerabilityDatabaseHandler.add(vulnerability);
if (RequestStatus.SUCCESS.equals(requestStatus)) {
statusToVulnerabilities.get(UpdateType.NEW).add(vulnerability);
return statusToVulnerabilities;
}
}
statusToVulnerabilities.get(UpdateType.FAILED).add(vulnerability);
return statusToVulnerabilities;
}
use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.
the class VulnerabilityUtils method reduceVulnerabilityUpdateStatus.
public static VulnerabilityUpdateStatus reduceVulnerabilityUpdateStatus(VulnerabilityUpdateStatus... statuses) {
VulnerabilityUpdateStatus resultStatus = getEmptyVulnerabilityUpdateStatus();
RequestStatus requestStatus = Arrays.stream(statuses).map(VulnerabilityUpdateStatus::getRequestStatus).reduce(RequestStatus.SUCCESS, CommonUtils::reduceRequestStatus);
resultStatus.setRequestStatus(requestStatus);
for (UpdateType updateType : UpdateType.values()) {
for (VulnerabilityUpdateStatus status : statuses) {
if (status.isSetStatusToVulnerabilityIds()) {
resultStatus.statusToVulnerabilityIds.get(updateType).addAll(nullToEmptyList(status.statusToVulnerabilityIds.get(updateType)));
}
}
}
return resultStatus;
}
use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.
the class ProjectDatabaseHandler method updateProject.
// /////////////////////////////
// UPDATE INDIVIDUAL OBJECTS //
// /////////////////////////////
public RequestStatus updateProject(Project project, User user) throws SW360Exception {
// Prepare project for database
prepareProject(project);
Project actual = repository.get(project.getId());
assertNotNull(project);
if (!changePassesSanityCheck(project, actual)) {
return RequestStatus.FAILED_SANITY_CHECK;
} else if (makePermission(actual, user).isActionAllowed(RequestedAction.WRITE)) {
copyImmutableFields(project, actual);
project.setAttachments(getAllAttachmentsToKeep(actual.getAttachments(), project.getAttachments()));
repository.update(project);
// clean up attachments in database
attachmentConnector.deleteAttachmentDifference(actual.getAttachments(), project.getAttachments());
sendMailNotificationsForProjectUpdate(project, user.getEmail());
return RequestStatus.SUCCESS;
} else {
return moderator.updateProject(project, user);
}
}
Aggregations