use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ProjectDatabaseHandler method getReleaseClearingStatuses.
public List<ReleaseClearingStatusData> getReleaseClearingStatuses(String projectId, User user) throws SW360Exception {
Project project = getProjectById(projectId, user);
SetMultimap<String, ProjectWithReleaseRelationTuple> releaseIdsToProject = releaseIdToProjects(project, user);
List<Release> releasesById = componentDatabaseHandler.getFullReleases(releaseIdsToProject.keySet());
Map<String, Component> componentsById = ThriftUtils.getIdMap(componentDatabaseHandler.getComponentsShort(releasesById.stream().map(Release::getComponentId).collect(Collectors.toSet())));
List<ReleaseClearingStatusData> releaseClearingStatuses = new ArrayList<>();
for (Release release : releasesById) {
List<String> projectNames = new ArrayList<>();
List<String> mainlineStates = new ArrayList<>();
for (ProjectWithReleaseRelationTuple projectWithReleaseRelation : releaseIdsToProject.get(release.getId())) {
projectNames.add(printName(projectWithReleaseRelation.getProject()));
mainlineStates.add(ThriftEnumUtils.enumToString(projectWithReleaseRelation.getRelation().getMainlineState()));
if (projectNames.size() > 3) {
projectNames.add("...");
mainlineStates.add("...");
break;
}
}
releaseClearingStatuses.add(new ReleaseClearingStatusData(release).setProjectNames(joinStrings(projectNames)).setMainlineStates(joinStrings(mainlineStates)).setComponentType(componentsById.get(release.getComponentId()).getComponentType()));
}
return releaseClearingStatuses;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception 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);
}
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ComponentDatabaseHandler method getComponentForEdit.
public Component getComponentForEdit(String id, User user) throws SW360Exception {
List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
Component component = getComponent(id, user);
DocumentState documentState;
if (moderationRequestsForDocumentId.isEmpty()) {
documentState = CommonUtils.getOriginalDocumentState();
} else {
final String email = user.getEmail();
Optional<ModerationRequest> moderationRequestOptional = CommonUtils.getFirstModerationRequestOfUser(moderationRequestsForDocumentId, email);
if (moderationRequestOptional.isPresent() && isInProgressOrPending(moderationRequestOptional.get())) {
ModerationRequest moderationRequest = moderationRequestOptional.get();
component = moderator.updateComponentFromModerationRequest(component, moderationRequest.getComponentAdditions(), moderationRequest.getComponentDeletions());
documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
} else {
documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
}
}
component.setPermissions(makePermission(component, user).getPermissionMap());
component.setDocumentState(documentState);
return component;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ComponentDatabaseHandler method getReleaseForEdit.
public Release getReleaseForEdit(String id, User user) throws SW360Exception {
List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
Release release = getRelease(id, user);
DocumentState documentState;
if (moderationRequestsForDocumentId.isEmpty()) {
documentState = CommonUtils.getOriginalDocumentState();
} else {
final String email = user.getEmail();
Optional<ModerationRequest> moderationRequestOptional = CommonUtils.getFirstModerationRequestOfUser(moderationRequestsForDocumentId, email);
if (moderationRequestOptional.isPresent() && isInProgressOrPending(moderationRequestOptional.get())) {
ModerationRequest moderationRequest = moderationRequestOptional.get();
release = releaseModerator.updateReleaseFromModerationRequest(release, moderationRequest.getReleaseAdditions(), moderationRequest.getReleaseDeletions());
documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
} else {
documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
}
}
vendorRepository.fillVendor(release);
release.setPermissions(makePermission(release, user).getPermissionMap());
release.setDocumentState(documentState);
ensureEccInformationIsSet(release);
return release;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ProjectDatabaseHandler method deleteProject.
// /////////////////////////////
// DELETE INDIVIDUAL OBJECTS //
// /////////////////////////////
public RequestStatus deleteProject(String id, User user) throws SW360Exception {
Project project = repository.get(id);
assertNotNull(project);
if (checkIfInUse(id)) {
return RequestStatus.IN_USE;
}
// Remove the project if the user is allowed to do it by himself
if (makePermission(project, user).isActionAllowed(RequestedAction.DELETE)) {
removeProjectAndCleanUp(project);
return RequestStatus.SUCCESS;
} else {
return moderator.deleteProject(project, user);
}
}
Aggregations