Search in sources :

Example 86 with User

use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.

the class LicensesPortlet method prepareDetailView.

private void prepareDetailView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    String id = request.getParameter(LICENSE_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    request.setAttribute(IS_USER_AT_LEAST_CLEARING_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user) ? "Yes" : "No");
    if (id != null) {
        try {
            LicenseService.Iface client = thriftClients.makeLicenseClient();
            License moderationLicense = client.getByIDWithOwnModerationRequests(id, user.getDepartment(), user);
            List<Todo> allTodos = nullToEmptyList(moderationLicense.getTodos());
            List<Todo> addedTodos = allTodos.stream().filter(CommonUtils::isTemporaryTodo).collect(Collectors.toList());
            List<Todo> currentTodos = allTodos.stream().filter(t -> !CommonUtils.isTemporaryTodo(t)).collect(Collectors.toList());
            request.setAttribute(ADDED_TODOS_FROM_MODERATION_REQUEST, addedTodos);
            request.setAttribute(DB_TODOS_FROM_MODERATION_REQUEST, currentTodos);
            request.setAttribute(MODERATION_LICENSE_DETAIL, moderationLicense);
            License dbLicense = client.getByID(id, user.getDepartment());
            request.setAttribute(KEY_LICENSE_DETAIL, dbLicense);
            List<Obligation> obligations = client.getObligations();
            request.setAttribute(KEY_OBLIGATION_LIST, obligations);
            addLicenseBreadcrumb(request, response, moderationLicense);
        } catch (TException e) {
            log.error("Error fetching license details from backend", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_LICENSE);
        }
    }
}
Also used : java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) PortletResponseUtil(com.liferay.portal.kernel.portlet.PortletResponseUtil) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) TMP_TODO_ID_PREFIX(org.eclipse.sw360.datahandler.common.CommonUtils.TMP_TODO_ID_PREFIX) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Function(java.util.function.Function) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Strings(com.google.common.base.Strings) Logger(org.apache.log4j.Logger) SessionMessages(com.liferay.portal.kernel.servlet.SessionMessages) CONTENT_TYPE_OPENXML_SPREADSHEET(org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET) ThriftEnumUtils(org.eclipse.sw360.datahandler.common.ThriftEnumUtils) Ternary(org.eclipse.sw360.datahandler.thrift.Ternary) javax.portlet(javax.portlet) org.eclipse.sw360.datahandler.thrift.licenses(org.eclipse.sw360.datahandler.thrift.licenses) Sw360Portlet(org.eclipse.sw360.portal.portlets.Sw360Portlet) ImmutableSet(com.google.common.collect.ImmutableSet) UserGroup(org.eclipse.sw360.datahandler.thrift.users.UserGroup) HttpServletResponse(javax.servlet.http.HttpServletResponse) TException(org.apache.thrift.TException) PermissionUtils(org.eclipse.sw360.datahandler.permissions.PermissionUtils) IOException(java.io.IOException) CommonUtils.nullToEmptyList(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyList) Collectors(java.util.stream.Collectors) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) ErrorMessages(org.eclipse.sw360.portal.common.ErrorMessages) EnumUtils(org.apache.commons.lang.enums.EnumUtils) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) LicenseExporter(org.eclipse.sw360.exporter.LicenseExporter) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 87 with User

use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.

the class LicensesPortlet method prepareStandardView.

private void prepareStandardView(RenderRequest request) {
    log.debug("Enter license table view");
    List<License> licenses;
    User user = UserCacheHolder.getUserFromRequest(request);
    request.setAttribute(IS_USER_AT_LEAST_CLEARING_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user) ? "Yes" : "No");
    try {
        LicenseService.Iface client = thriftClients.makeLicenseClient();
        licenses = client.getLicenseSummary();
    } catch (TException e) {
        log.error("Could not fetch license summary from backend!", e);
        licenses = new ArrayList<>();
    }
    request.setAttribute(LICENSE_LIST, licenses);
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 88 with User

use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.

the class LicensesPortlet method prepareEditView.

private void prepareEditView(RenderRequest request, RenderResponse response) {
    String id = request.getParameter(LICENSE_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    LicenseService.Iface client = thriftClients.makeLicenseClient();
    try {
        licenseTypes = client.getLicenseTypes();
        request.setAttribute(LICENSE_TYPE_CHOICE, licenseTypes);
    } catch (TException e) {
        log.error("Error fetching license types from backend", e);
        setSW360SessionError(request, ErrorMessages.ERROR_GETTING_LICENSE);
    }
    if (id != null) {
        try {
            License license = client.getByID(id, user.getDepartment());
            request.setAttribute(KEY_LICENSE_DETAIL, license);
            addLicenseBreadcrumb(request, response, license);
        } catch (TException e) {
            log.error("Error fetching license details from backend", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_LICENSE);
        }
    } else {
        if (request.getAttribute(KEY_LICENSE_DETAIL) == null) {
            SessionMessages.add(request, "request_processed", "New License");
            License license = new License();
            request.setAttribute(KEY_LICENSE_DETAIL, license);
        }
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 89 with User

use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.

the class LicensesPortlet method update.

@UsedAsLiferayAction
public void update(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    LicenseService.Iface client = thriftClients.makeLicenseClient();
    String licenseId = request.getParameter(LICENSE_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    License license = prepareLicenseForUpdate(request, client, licenseId, user);
    boolean isNewLicense = isNullOrEmpty(licenseId);
    boolean isAttemptToOverwriteExistingByNew = isAttemptToOverwriteExistingByNew(license, user, isNewLicense, client);
    RequestStatus requestStatus = updateLicense(license, user, isAttemptToOverwriteExistingByNew, client);
    if (isAttemptToOverwriteExistingByNew) {
        response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
        setSW360SessionError(request, ErrorMessages.LICENSE_SHORTNAME_TAKEN);
        request.setAttribute(KEY_LICENSE_DETAIL, license);
    } else if (isNewLicense) {
        response.setRenderParameter(PAGENAME, PAGENAME_VIEW);
        setSessionMessage(request, requestStatus, "License", "adde");
    } else {
        response.setRenderParameter(LICENSE_ID, licenseId);
        response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
        response.setRenderParameter(SELECTED_TAB, "Details");
        setSessionMessage(request, requestStatus, "License", "update");
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 90 with User

use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.

the class AttachmentAwarePortlet method doGetAttachmentForDisplay.

private void doGetAttachmentForDisplay(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
    final String attachmentId = request.getParameter(PortalConstants.ATTACHMENT_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    Attachment attachment = attachmentPortletUtils.getAttachmentForDisplay(user, attachmentId);
    if (attachment == null) {
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "500");
    } else {
        writeJSON(request, response, OBJECT_MAPPER.writeValueAsString(attachment));
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)169 TException (org.apache.thrift.TException)100 Release (org.eclipse.sw360.datahandler.thrift.components.Release)58 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)44 Test (org.junit.Test)30 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)27 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)26 Component (org.eclipse.sw360.datahandler.thrift.components.Component)20 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)20 ResponseEntity (org.springframework.http.ResponseEntity)20 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)19 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)18 IOException (java.io.IOException)17 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)16 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)16 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)13 RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)12 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)12 Before (org.junit.Before)12 ArrayList (java.util.ArrayList)11