Search in sources :

Example 26 with ModerationRequest

use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.

the class ModerationPortlet method renderActionView.

private void renderActionView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    final String id = request.getParameter(MODERATION_ID);
    String sessionMessage;
    if (id != null) {
        try {
            ModerationService.Iface client = thriftClients.makeModerationClient();
            ModerationRequest moderationRequest = client.getModerationRequestById(id);
            String action = request.getParameter(ACTION);
            String encodedModerationComment = request.getParameter(MODERATION_DECISION_COMMENT);
            String moderationComment = "";
            if (encodedModerationComment != null) {
                moderationComment = new String(Base64.getDecoder().decode(encodedModerationComment));
            }
            if (ACTION_CANCEL.equals(action)) {
                client.cancelInProgress(id);
                sessionMessage = "You have cancelled working on the previous moderation request.";
            } else if (ACTION_DECLINE.equals(action)) {
                declineModerationRequest(user, moderationRequest, request);
                client.refuseRequest(id, moderationComment, user.getEmail());
                sessionMessage = "You have declined the previous moderation request.";
            } else if (ACTION_ACCEPT.equals(action)) {
                String requestingUserEmail = moderationRequest.getRequestingUser();
                User requestingUser = UserCacheHolder.getUserFromEmail(requestingUserEmail);
                acceptModerationRequest(user, requestingUser, moderationRequest, request);
                client.acceptRequest(moderationRequest, moderationComment, user.getEmail());
                sessionMessage = "You have accepted the previous moderation request.";
            } else if (ACTION_POSTPONE.equals(action)) {
                // keep me assigned but do it later... so nothing to be done here, just update the comment message
                moderationRequest.setCommentDecisionModerator(moderationComment);
                client.updateModerationRequest(moderationRequest);
                sessionMessage = "You have postponed the previous moderation request.";
            } else if (ACTION_RENDER_NEXT_AFTER_UNSUBSCRIBE.equals(action)) {
                sessionMessage = "You are removed from the list of moderators for the previous moderation request.";
            } else {
                throw new PortletException("Unknown action");
            }
            // ! Actions are processed now we go and render the next one
            renderNextModeration(request, response, user, sessionMessage, client, moderationRequest);
        } catch (TException e) {
            log.error("Error in Moderation ", e);
        }
    }
}
Also used : ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 27 with ModerationRequest

use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.

the class MyTaskSubmissionsPortlet method doView.

@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    List<ModerationRequest> moderations = null;
    try {
        final User user = UserCacheHolder.getUserFromRequest(request);
        moderations = thriftClients.makeModerationClient().getRequestsByRequestingUser(user);
    } catch (TException e) {
        log.error("Could not fetch your moderations from backend", e);
    }
    request.setAttribute(PortalConstants.MODERATION_REQUESTS, CommonUtils.nullToEmptyList(moderations));
    super.doView(request, response);
}
Also used : TException(org.apache.thrift.TException) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 28 with ModerationRequest

use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.

the class ModerationPortlet method renderComponentModeration.

public void renderComponentModeration(RenderRequest request, RenderResponse response, ModerationRequest moderationRequest, User user) throws IOException, PortletException, TException {
    final boolean requestDocumentDelete = moderationRequest.isRequestDocumentDelete();
    Boolean is_used = false;
    Component actual_component = null;
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        actual_component = client.getComponentById(moderationRequest.getDocumentId(), user);
        is_used = client.componentIsUsed(actual_component.getId());
    } catch (TException e) {
        log.error("Could not retrieve component", e);
    }
    if (actual_component == null) {
        renderNextModeration(request, response, user, "Ignored unretrievable target", thriftClients.makeModerationClient(), moderationRequest);
        return;
    }
    if (refuseToDeleteUsedDocument(request, response, moderationRequest, user, requestDocumentDelete, is_used))
        return;
    prepareComponent(request, user, actual_component);
    request.setAttribute(PortalConstants.ACTUAL_COMPONENT, actual_component);
    if (moderationRequest.isRequestDocumentDelete()) {
        include("/html/moderation/components/delete.jsp", request, response);
    } else {
        include("/html/moderation/components/merge.jsp", request, response);
    }
}
Also used : TException(org.apache.thrift.TException) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Example 29 with ModerationRequest

use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.

the class DatabaseTestSetup method main.

public static void main(String[] args) throws MalformedURLException {
    DatabaseConnector db = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), DatabaseSettings.COUCH_DB_DATABASE);
    Project project = new Project().setName("Test Project");
    project.addToModerators("user1");
    db.add(project);
    ModerationRequest moderationRequest = new ModerationRequest();
    moderationRequest.setDocumentId(project.id).setDocumentType(DocumentType.PROJECT);
    moderationRequest.setRequestingUser("cedric.bodet@tngtech.com");
    moderationRequest.addToModerators("cedric.bodet@tngtech.com");
    db.add(moderationRequest);
}
Also used : DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 30 with ModerationRequest

use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.

the class TestModerationClient method main.

public static void main(String[] args) throws TException, IOException {
    THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080//moderation/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    ModerationService.Iface client = new ModerationService.Client(protocol);
    List<ModerationRequest> requestsByModerator = client.getRequestsByModerator(new User().setId("").setEmail("cedric.bodet@tngtech.com").setDepartment("BB"));
    System.out.println("Fetched " + requestsByModerator.size() + " moderation requests from moderation service");
}
Also used : ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) User(org.eclipse.sw360.datahandler.thrift.users.User) TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) THttpClient(org.apache.thrift.transport.THttpClient)

Aggregations

ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)24 TException (org.apache.thrift.TException)11 User (org.eclipse.sw360.datahandler.thrift.users.User)8 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)5 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Component (org.eclipse.sw360.datahandler.thrift.components.Component)4 ModerationService (org.eclipse.sw360.datahandler.thrift.moderation.ModerationService)4 Release (org.eclipse.sw360.datahandler.thrift.components.Release)3 License (org.eclipse.sw360.datahandler.thrift.licenses.License)3 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)2 Organization (com.liferay.portal.model.Organization)1 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 THttpClient (org.apache.thrift.transport.THttpClient)1 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)1 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)1 DocumentState (org.eclipse.sw360.datahandler.thrift.DocumentState)1 COTSDetails (org.eclipse.sw360.datahandler.thrift.components.COTSDetails)1 LicenseService (org.eclipse.sw360.datahandler.thrift.licenses.LicenseService)1 Obligation (org.eclipse.sw360.datahandler.thrift.licenses.Obligation)1