Search in sources :

Example 26 with SW360Exception

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

Example 27 with SW360Exception

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

Example 28 with SW360Exception

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

Example 29 with SW360Exception

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

Example 30 with SW360Exception

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

Aggregations

SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)23 IOException (java.io.IOException)10 InputStream (java.io.InputStream)9 TException (org.apache.thrift.TException)9 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)9 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)9 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)8 Release (org.eclipse.sw360.datahandler.thrift.components.Release)5 User (org.eclipse.sw360.datahandler.thrift.users.User)5 Test (org.junit.Test)4 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)3 SW360Utils.fieldValueAsString (org.eclipse.sw360.datahandler.common.SW360Utils.fieldValueAsString)3 Component (org.eclipse.sw360.datahandler.thrift.components.Component)3 JSchException (com.jcraft.jsch.JSchException)2 Session (com.jcraft.jsch.Session)2 PipedInputStream (java.io.PipedInputStream)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 ConcatClosingInputStream (org.eclipse.sw360.datahandler.common.ConcatClosingInputStream)2 WrappedSW360Exception (org.eclipse.sw360.datahandler.common.WrappedException.WrappedSW360Exception)2