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