Search in sources :

Example 1 with CommonUtils.nullToEmptyString

use of org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString 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 2 with CommonUtils.nullToEmptyString

use of org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString in project sw360portal by sw360.

the class LicensesPortlet method editExternalLink.

@UsedAsLiferayAction
public void editExternalLink(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String licenseId = request.getParameter(LICENSE_ID);
    String remoteLink = request.getParameter(License._Fields.EXTERNAL_LICENSE_LINK.name());
    if (!Strings.isNullOrEmpty(licenseId)) {
        try {
            User user = UserCacheHolder.getUserFromRequest(request);
            LicenseService.Iface client = thriftClients.makeLicenseClient();
            final License license = client.getByID(licenseId, user.getDepartment());
            license.setExternalLicenseLink(CommonUtils.nullToEmptyString(remoteLink));
            final RequestStatus requestStatus = client.updateLicense(license, user, user);
            renderRequestStatus(request, response, requestStatus);
        } catch (TException e) {
            log.error("Error updating license", e);
        }
    }
    response.setRenderParameter(LICENSE_ID, licenseId);
    response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
    response.setRenderParameter(SELECTED_TAB, "Details");
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 3 with CommonUtils.nullToEmptyString

use of org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString in project sw360portal by sw360.

the class LicensesPortlet method changeText.

@UsedAsLiferayAction
public void changeText(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String licenseId = request.getParameter(LICENSE_ID);
    String text = request.getParameter(License._Fields.TEXT.name());
    if (!isNullOrEmpty(licenseId)) {
        try {
            User user = UserCacheHolder.getUserFromRequest(request);
            LicenseService.Iface client = thriftClients.makeLicenseClient();
            final License license = client.getByID(licenseId, user.getDepartment());
            license.setText(CommonUtils.nullToEmptyString(text));
            final RequestStatus requestStatus = client.updateLicense(license, user, user);
            renderRequestStatus(request, response, requestStatus);
        } catch (TException e) {
            log.error("Error updating license", e);
        }
    }
    response.setRenderParameter(LICENSE_ID, licenseId);
    response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
    response.setRenderParameter(SELECTED_TAB, "LicenseText");
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Aggregations

TException (org.apache.thrift.TException)3 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)2 User (org.eclipse.sw360.datahandler.thrift.users.User)2 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)2 Ternary (org.eclipse.sw360.datahandler.thrift.Ternary)1