Search in sources :

Example 76 with Project

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;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple)

Example 77 with Project

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);
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 78 with Project

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;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 79 with Project

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);
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 80 with Project

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;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Aggregations

Project (org.eclipse.sw360.datahandler.thrift.projects.Project)87 User (org.eclipse.sw360.datahandler.thrift.users.User)46 Test (org.junit.Test)42 TException (org.apache.thrift.TException)27 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)16 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)12 Release (org.eclipse.sw360.datahandler.thrift.components.Release)12 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)10 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)7 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)6 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 HashSet (java.util.HashSet)5 ResponseEntity (org.springframework.http.ResponseEntity)5