Search in sources :

Example 1 with Comment

use of org.eclipse.sw360.datahandler.thrift.Comment in project sw360 by eclipse.

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;
    ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", request.getLocale(), getClass());
    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 = LanguageUtil.get(resourceBundle, "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 = LanguageUtil.get(resourceBundle, "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 = LanguageUtil.get(resourceBundle, "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 = LanguageUtil.get(resourceBundle, "you.have.postponed.the.previous.moderation.request");
            } else if (ACTION_RENDER_NEXT_AFTER_UNSUBSCRIBE.equals(action)) {
                sessionMessage = LanguageUtil.get(resourceBundle, "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) WrappedException.wrapTException(org.eclipse.sw360.datahandler.common.WrappedException.wrapTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 2 with Comment

use of org.eclipse.sw360.datahandler.thrift.Comment in project sw360 by eclipse.

the class ModerationPortletUtils method reOpenClearingRequest.

private static AddDocumentRequestSummary reOpenClearingRequest(String id, PortletRequest request, User user) {
    AddDocumentRequestSummary requestSummary = new AddDocumentRequestSummary().setRequestStatus(AddDocumentRequestStatus.FAILURE);
    try {
        ModerationService.Iface client = new ThriftClients().makeModerationClient();
        Integer criticalCount = client.getCriticalClearingRequestCount();
        String preferredDate = request.getParameter(ClearingRequest._Fields.REQUESTED_CLEARING_DATE.toString());
        String commentText = request.getParameter(ClearingRequest._Fields.REQUESTING_USER_COMMENT.toString());
        String priority = (criticalCount > 1) ? "" : request.getParameter(ClearingRequest._Fields.PRIORITY.toString());
        Integer dateLimit = ModerationPortletUtils.loadPreferredClearingDateLimit(request, user);
        dateLimit = (CommonUtils.isNotNullEmptyOrWhitespace(priority) && criticalCount < 2) ? 0 : (dateLimit < 1) ? 7 : dateLimit;
        if (!SW360Utils.isValidDate(preferredDate, DateTimeFormatter.ISO_LOCAL_DATE, Long.valueOf(dateLimit))) {
            log.warn("Invalid requested clearing date: " + preferredDate + " is entered, by user: " + user.getEmail());
            return requestSummary.setMessage("Invalid requested clearing date");
        }
        ClearingRequest clearingRequest = client.getClearingRequestByIdForEdit(id, user);
        if (CommonUtils.isNotNullEmptyOrWhitespace(commentText)) {
            commentText = "Reopen comment:\n" + commentText;
            Comment comment = new Comment(commentText, user.getEmail());
            comment.setAutoGenerated(true);
            comment.setCommentedOn(System.currentTimeMillis());
            clearingRequest.addToComments(comment);
        }
        clearingRequest.setRequestedClearingDate(preferredDate);
        clearingRequest.unsetAgreedClearingDate();
        clearingRequest.setClearingState(ClearingRequestState.NEW);
        clearingRequest.unsetTimestampOfDecision();
        if (CommonUtils.isNotNullEmptyOrWhitespace(priority)) {
            clearingRequest.setPriority(ClearingRequestPriority.CRITICAL);
        } else {
            clearingRequest.setPriority(ClearingRequestPriority.LOW);
        }
        clearingRequest.addToReOpenOn(System.currentTimeMillis());
        LiferayPortletURL projectUrl = getProjectPortletUrl(request, clearingRequest.getProjectId());
        RequestStatus status = client.updateClearingRequest(clearingRequest, user, CommonUtils.nullToEmptyString(projectUrl));
        if (RequestStatus.SUCCESS.equals(status)) {
            return new AddDocumentRequestSummary().setRequestStatus(AddDocumentRequestStatus.SUCCESS).setId(id);
        } else {
            return requestSummary.setMessage("Failed to reopen clearing request");
        }
    } catch (TException e) {
        log.error("Failed to re-open clearing request", e);
    }
    return requestSummary.setMessage("Failed to reopen clearing request");
}
Also used : ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService) TException(org.apache.thrift.TException) AddDocumentRequestSummary(org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary) Comment(org.eclipse.sw360.datahandler.thrift.Comment) ClearingRequest(org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest) LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients) AddDocumentRequestStatus(org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 3 with Comment

use of org.eclipse.sw360.datahandler.thrift.Comment in project sw360 by eclipse.

the class ModerationPortletUtils method addCommentToClearingRequest.

public static RequestStatus addCommentToClearingRequest(PortletRequest request, Logger log) {
    String id = request.getParameter(PortalConstants.CLEARING_REQUEST_ID);
    String commentText = request.getParameter(PortalConstants.CLEARING_REQUEST_COMMENT);
    if (CommonUtils.isNullEmptyOrWhitespace(commentText)) {
        log.warn("Invalid comment, (empty or whitespace)");
        return RequestStatus.FAILURE;
    }
    User user = UserCacheHolder.getUserFromRequest(request);
    Comment comment = new Comment(commentText, user.getEmail());
    try {
        ModerationService.Iface client = new ThriftClients().makeModerationClient();
        return client.addCommentToClearingRequest(id, comment, user);
    } catch (TException e) {
        log.error("failed to add comment in clearing reuest: " + id, e);
    }
    return RequestStatus.FAILURE;
}
Also used : ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService) TException(org.apache.thrift.TException) Comment(org.eclipse.sw360.datahandler.thrift.Comment) User(org.eclipse.sw360.datahandler.thrift.users.User) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Example 4 with Comment

use of org.eclipse.sw360.datahandler.thrift.Comment in project sw360 by eclipse.

the class DisplayDownloadApprovedClearingReportTest method testThatFieldsAreEscapedForTitle.

@Test
public void testThatFieldsAreEscapedForTitle() {
    Attachment attachment = createAttachment("F<>&'\"F");
    attachment.setCheckedBy("AB<>&'\"AB");
    attachment.setCheckedOn("AO<>&'\"AO");
    attachment.setCheckedComment("CC<>&'\"CC");
    attachment.setCreatedBy("CB<>&'\"CB");
    attachment.setCreatedOn("CO<>&'\"CO");
    attachment.setCheckStatus(CheckStatus.ACCEPTED);
    DisplayDownloadApprovedClearingReport displayDownloadAttachment = new DisplayDownloadApprovedClearingReport();
    displayDownloadAttachment.setAttachment(attachment);
    assertEquals("Filename: F&lt;&gt;&amp;&#39;&quot;F&#010;Status: APPROVED by AB&lt;&gt;&amp;&#39;&quot;AB on AO&lt;&gt;&amp;&#39;&quot;AO&#010;Comment: CC&lt;&gt;&amp;&#39;&quot;CC&#010;Created: CB&lt;&gt;&amp;&#39;&quot;CB on CO&lt;&gt;&amp;&#39;&quot;CO", displayDownloadAttachment.getTitleText());
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 5 with Comment

use of org.eclipse.sw360.datahandler.thrift.Comment in project sw360 by eclipse.

the class ProjectSpecTest method should_document_update_project_attachment_info.

@Test
public void should_document_update_project_attachment_info() throws Exception {
    Attachment updateAttachment = new Attachment().setAttachmentType(AttachmentType.BINARY).setCreatedComment("Created Comment").setCheckStatus(CheckStatus.ACCEPTED).setCheckedComment("Checked Comment");
    String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
    this.mockMvc.perform(patch("/api/projects/98745/attachment/1234").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(updateAttachment)).header("Authorization", "Bearer " + accessToken).accept(MediaTypes.HAL_JSON)).andExpect(status().isOk()).andDo(this.documentationHandler.document(requestFields(fieldWithPath("attachmentType").description("The type of Attachment. Possible Values are: " + Arrays.asList(AttachmentType.values())), fieldWithPath("createdComment").description("The upload Comment of Attachment"), fieldWithPath("checkStatus").description("The checkStatus of Attachment. Possible Values are: " + Arrays.asList(CheckStatus.values())), fieldWithPath("checkedComment").description("The checked Comment of Attachment")), responseFields(fieldWithPath("filename").description("The attachment filename"), fieldWithPath("sha1").description("The attachment sha1 value"), fieldWithPath("attachmentType").description("The type of attachment. Possible Values are: " + Arrays.asList(AttachmentType.values())), fieldWithPath("createdBy").description("The email of user who uploaded the attachment"), fieldWithPath("createdTeam").description("The department of user who uploaded the attachment"), fieldWithPath("createdOn").description("The date when attachment was uploaded"), fieldWithPath("createdComment").description("The upload Comment of attachment"), fieldWithPath("checkStatus").description("The checkStatus of attachment. Possible Values are: " + Arrays.asList(CheckStatus.values())), fieldWithPath("checkedComment").description("The checked comment of attachment"), fieldWithPath("checkedBy").description("The email of user who checked the attachment"), fieldWithPath("checkedTeam").description("The department of user who checked the attachment"), fieldWithPath("checkedOn").description("The date when attachment was checked"), subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources"))));
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Aggregations

Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)17 Test (org.junit.Test)16 User (org.eclipse.sw360.datahandler.thrift.users.User)13 TException (org.apache.thrift.TException)6 Comment (org.eclipse.sw360.datahandler.thrift.Comment)5 ProjectReleaseRelationship (org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship)5 AttachmentType (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType)5 Release (org.eclipse.sw360.datahandler.thrift.components.Release)5 ClearingRequest (org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest)5 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)5 Before (org.junit.Before)5 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)4 ArrayList (java.util.ArrayList)3 WrappedException.wrapTException (org.eclipse.sw360.datahandler.common.WrappedException.wrapTException)3 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)3 Source (org.eclipse.sw360.datahandler.thrift.Source)3 ModerationService (org.eclipse.sw360.datahandler.thrift.moderation.ModerationService)3 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)3 Resource (org.springframework.hateoas.Resource)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2