Search in sources :

Example 11 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License 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 12 with License

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

the class LicensesPortlet method updateLicenseFromRequest.

private License updateLicenseFromRequest(License license, ActionRequest request) {
    String text = request.getParameter(License._Fields.TEXT.name());
    String fullname = request.getParameter(License._Fields.FULLNAME.name());
    String shortname = request.getParameter(License._Fields.SHORTNAME.name());
    Ternary gpl2compatibility = Ternary.findByValue(Integer.parseInt(request.getParameter(License._Fields.GPLV2_COMPAT.toString())));
    Ternary gpl3compatibility = Ternary.findByValue(Integer.parseInt(request.getParameter(License._Fields.GPLV3_COMPAT.toString())));
    String licenseTypeString = request.getParameter(License._Fields.LICENSE_TYPE.toString() + LicenseType._Fields.LICENSE_TYPE.toString());
    license.setText(CommonUtils.nullToEmptyString(text));
    license.setFullname(CommonUtils.nullToEmptyString(fullname));
    license.setShortname((CommonUtils.nullToEmptyString(shortname)));
    license.setGPLv2Compat(gpl2compatibility);
    license.setGPLv3Compat(gpl3compatibility);
    try {
        Optional<String> licenseTypeDatabaseId = getDatabaseIdFromLicenseType(licenseTypeString);
        if (licenseTypeDatabaseId.isPresent()) {
            license.setLicenseTypeDatabaseId(licenseTypeDatabaseId.get());
            final LicenseType licenseType = thriftClients.makeLicenseClient().getLicenseTypeById(license.getLicenseTypeDatabaseId());
            license.setLicenseType(licenseType);
        } else {
            license.unsetLicenseTypeDatabaseId();
        }
    } catch (TException e) {
        log.error("Could not set licenseTypeDatabaseId:" + e);
        license.unsetLicenseTypeDatabaseId();
    }
    return license;
}
Also used : TException(org.apache.thrift.TException) Ternary(org.eclipse.sw360.datahandler.thrift.Ternary)

Example 13 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License 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 14 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License 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 15 with License

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

the class TestLicenseClient method main.

public static void main(String[] args) throws TException, IOException {
    THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080/licenses/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    LicenseService.Iface client = new LicenseService.Client(protocol);
    List<License> licenses = client.getLicenseSummary();
    List<Obligation> obligations = client.getObligations();
    System.out.println("Fetched " + licenses.size() + " licenses from license service");
    System.out.println("Fetched " + obligations.size() + " obligations from license service");
    // final List<License> licenseList = client.getDetailedLicenseSummaryForExport("");
    final List<License> licenseList = client.getDetailedLicenseSummary("", ImmutableList.of("AFL-2.1", "Artistic-1.0"));
    System.out.println(licenseList.toString());
}
Also used : Obligation(org.eclipse.sw360.datahandler.thrift.licenses.Obligation) TProtocol(org.apache.thrift.protocol.TProtocol) LicenseService(org.eclipse.sw360.datahandler.thrift.licenses.LicenseService) License(org.eclipse.sw360.datahandler.thrift.licenses.License) THttpClient(org.apache.thrift.transport.THttpClient) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) THttpClient(org.apache.thrift.transport.THttpClient)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)20 TException (org.apache.thrift.TException)16 License (org.eclipse.sw360.datahandler.thrift.licenses.License)16 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)8 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)7 java.util (java.util)5 Collectors (java.util.stream.Collectors)5 Logger (org.apache.log4j.Logger)5 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)5 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)5 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Release (org.eclipse.sw360.datahandler.thrift.components.Release)4 Maps (com.google.common.collect.Maps)3 Sets (com.google.common.collect.Sets)3 XWPFRun (org.apache.poi.xwpf.usermodel.XWPFRun)3 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)3 Ternary (org.eclipse.sw360.datahandler.thrift.Ternary)3 LicenseService (org.eclipse.sw360.datahandler.thrift.licenses.LicenseService)3 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3