Search in sources :

Example 11 with ThriftClients

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

the class DisplayUserEdit method doStartTag.

public int doStartTag() throws JspException {
    JspWriter jspWriter = pageContext.getOut();
    StringBuilder display = new StringBuilder();
    List<String> userList = new ArrayList<>();
    List<String> emailList = new ArrayList<>();
    List<String> emailInput;
    if (multiUsers) {
        emailInput = emails;
    } else {
        emailInput = new ArrayList<>();
        emailInput.add(email);
    }
    String namespace = getNamespace();
    try {
        UserService.Iface client = new ThriftClients().makeUserClient();
        for (String email : emailInput) {
            User user = null;
            try {
                if (!Strings.isNullOrEmpty(email))
                    user = client.getByEmail(email);
            } catch (TException e) {
                log.info("User with email=" + email + " not found in DB");
            }
            emailList.add(email);
            if (user != null) {
                userList.add(user.getFullname());
            } else {
                userList.add(email);
            }
        }
        Joiner commaJoiner = Joiner.on(", ");
        String mails = getString(commaJoiner.join(emailList));
        String userNames = getString(commaJoiner.join(userList));
        display.append(String.format("<label class=\"textlabel stackedLabel\" for=\"%sDisplay\">%s</label>", id, description)).append(String.format("<input type=\"hidden\" readonly=\"\" value=\"%s\"  id=\"%s\" name=\"%s%s\"/>", mails, id, namespace, id)).append(String.format("<input type=\"text\" readonly=\"\" value=\"%s\" id=\"%sDisplay\" ", userNames, id));
        if (!readonly) {
            display.append(String.format(" placeholder=\"Click to edit\" class=\"clickable userSearchDialogInteractive\" data-id=\"%s\" data-multi-user=\"%s\"", id, multiUsers ? "true" : "false"));
        } else {
            display.append(" placeholder=\"Will be set automatically\" ");
        }
        display.append("/>");
        jspWriter.print(display.toString());
    } catch (Exception e) {
        throw new JspException(e);
    }
    return SKIP_BODY;
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) Joiner(com.google.common.base.Joiner) UserService(org.eclipse.sw360.datahandler.thrift.users.UserService) ArrayList(java.util.ArrayList) JspWriter(javax.servlet.jsp.JspWriter) JspException(javax.servlet.jsp.JspException) TException(org.apache.thrift.TException) JspException(javax.servlet.jsp.JspException) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Example 12 with ThriftClients

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

the class ScheduleHandler method scheduleService.

@Override
public RequestSummary scheduleService(String serviceName) throws TException {
    if (ScheduleConstants.invalidConfiguredServices.contains(serviceName)) {
        log.info("Could not schedule " + serviceName + " because of invalid configuration.");
        return new RequestSummary(RequestStatus.FAILURE);
    }
    Scheduler.cancelSyncJobOfService(serviceName);
    boolean successSync = false;
    switch(serviceName) {
        case ThriftClients.CVESEARCH_SERVICE:
            successSync = wrapSupplierException(() -> thriftClients.makeCvesearchClient().update(), serviceName);
            break;
        default:
            log.error("Could not schedule service: " + serviceName + ". Reason: service is not registered in ThriftClients.");
    }
    if (successSync) {
        RequestSummary summary = new RequestSummary(RequestStatus.SUCCESS);
        summary.setMessage(SW360Utils.getDateTimeString(Scheduler.getNextSync()));
        return summary;
    } else {
        return new RequestSummary(RequestStatus.FAILURE);
    }
}
Also used : RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary)

Example 13 with ThriftClients

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

the class ComponentAndAttachmentAwareDBTest method setUp.

@Before
public void setUp() throws Exception {
    deleteDatabases();
    ThriftClients thriftClients = getThriftClients();
    componentClient = thriftClients.makeComponentClient();
    vendorClient = thriftClients.makeVendorClient();
    attachmentClient = thriftClients.makeAttachmentClient();
    attachmentRepository = getAttachmentRepository();
    user = getAdminUser(getClass());
}
Also used : ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients) Before(org.junit.Before)

Example 14 with ThriftClients

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

the class ScheduleAdminPortlet method unscheduleCveSearch.

@UsedAsLiferayAction
public void unscheduleCveSearch(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    try {
        User user = UserCacheHolder.getUserFromRequest(request);
        RequestStatus requestStatus = new ThriftClients().makeScheduleClient().unscheduleService(ThriftClients.CVESEARCH_SERVICE, user);
        setSessionMessage(request, requestStatus, "Task", "unschedule");
    } catch (TException e) {
        log.error(e);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 15 with ThriftClients

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

the class ComponentPortletUtils method deleteRelease.

public static RequestStatus deleteRelease(PortletRequest request, Logger log) {
    String releaseId = request.getParameter(PortalConstants.RELEASE_ID);
    if (releaseId != null) {
        try {
            String deleteCommentEncoded = request.getParameter(PortalConstants.MODERATION_REQUEST_COMMENT);
            User user = UserCacheHolder.getUserFromRequest(request);
            if (deleteCommentEncoded != null) {
                String deleteComment = new String(Base64.getDecoder().decode(deleteCommentEncoded));
                user.setCommentMadeDuringModerationRequest(deleteComment);
            }
            ComponentService.Iface client = new ThriftClients().makeComponentClient();
            return client.deleteRelease(releaseId, UserCacheHolder.getUserFromRequest(request));
        } catch (TException e) {
            log.error("Could not delete release from DB", e);
        }
    }
    return RequestStatus.FAILURE;
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Aggregations

TException (org.apache.thrift.TException)17 User (org.eclipse.sw360.datahandler.thrift.users.User)12 ThriftClients (org.eclipse.sw360.datahandler.thrift.ThriftClients)10 JspException (javax.servlet.jsp.JspException)3 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)3 HashMap (java.util.HashMap)2 JspWriter (javax.servlet.jsp.JspWriter)2 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)2 Release (org.eclipse.sw360.datahandler.thrift.components.Release)2 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)2 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)2 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)2 UserService (org.eclipse.sw360.datahandler.thrift.users.UserService)2 VendorService (org.eclipse.sw360.datahandler.thrift.vendors.VendorService)2 Before (org.junit.Before)2 Joiner (com.google.common.base.Joiner)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AttachmentHandler (org.eclipse.sw360.attachments.AttachmentHandler)1 ComponentHandler (org.eclipse.sw360.components.ComponentHandler)1