use of org.eclipse.sw360.datahandler.thrift.projects.Project 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.projects.Project 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.projects.Project in project sw360portal by sw360.
the class ProjectDatabaseHandler method getProjectsById.
public List<Project> getProjectsById(List<String> id, User user) {
List<Project> projects = repository.makeSummaryFromFullDocs(SummaryType.SUMMARY, repository.get(id));
List<Project> output = new ArrayList<>();
for (Project project : projects) {
if (makePermission(project, user).isActionAllowed(RequestedAction.READ)) {
output.add(project);
} else {
log.error("User " + user.getEmail() + " requested not accessible project " + printName(project));
}
}
return output;
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project 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);
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectDatabaseHandler method getProjectForEdit.
public Project getProjectForEdit(String id, User user) throws SW360Exception {
List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
Project project = getProjectById(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();
project = moderator.updateProjectFromModerationRequest(project, moderationRequest.getProjectAdditions(), moderationRequest.getProjectDeletions());
documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
} else {
documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
}
}
project.setPermissions(makePermission(project, user).getPermissionMap());
project.setDocumentState(documentState);
return project;
}
Aggregations