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;
}
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");
}
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");
}
Aggregations