use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class ProjectPortletUtils method getExcludedLicensesPerAttachmentIdFromRequest.
/**
* Returns a map of excluded licenses. They key is an attachment content id, the
* value is a list of excluded licenses.
* <p>
* For this method to work it is crucial that there is a so called
* "license-store-<attachmentContentId>" map in the session. This map must
* contain a mapping from a key to a {@link LicenseNameWithText} object.
*
* @param attachmentContentIds list of attachment content id to check for exclusions in the
* request
* @param request the request containing the excluded licenses as parameters
* @return a map containing the licenses to exclude
* @see ProjectPortletUtilsTest for a better understanding
*/
public static Map<String, Set<LicenseNameWithText>> getExcludedLicensesPerAttachmentIdFromRequest(Set<String> attachmentContentIds, ResourceRequest request) {
Map<String, Set<LicenseNameWithText>> excludedLicenses = Maps.newHashMap();
for (String attachmentContentId : attachmentContentIds) {
String[] checkboxes = request.getParameterValues(attachmentContentId);
String[] keys = request.getParameterValues(attachmentContentId + "_key");
if (checkboxes == null) {
// no details present
continue;
}
@SuppressWarnings("unchecked") Map<String, LicenseNameWithText> licenseStore = (Map<String, LicenseNameWithText>) request.getPortletSession().getAttribute(ProjectPortlet.LICENSE_STORE_KEY_PREFIX + attachmentContentId);
if (licenseStore == null) {
throw new IllegalStateException("No license store found for attachment content id " + attachmentContentId);
}
Set<Integer> includedIds = Arrays.stream(checkboxes).map(s -> Integer.valueOf(s)).collect(Collectors.toSet());
Set<LicenseNameWithText> licenseNameWithTexts = Sets.newHashSet();
for (int index = 0; index < keys.length; index++) {
if (includedIds.contains(index)) {
// transferred
continue;
}
LicenseNameWithText licenseNameWithText = licenseStore.get(keys[index]);
if (licenseNameWithText == null) {
throw new IllegalStateException("No license found for key " + keys[index]);
}
licenseNameWithTexts.add(licenseNameWithText);
}
excludedLicenses.put(attachmentContentId, licenseNameWithTexts);
}
return excludedLicenses;
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class CompareAttachments method renderCompareAttachment.
private void renderCompareAttachment(StringBuilder display, Attachment old, Attachment deleted, Attachment added) {
if (old.equals(added))
return;
display.append(String.format("<table class=\"%s\" id=\"%schanges%s\" >", tableClasses, idPrefix, old.getAttachmentContentId()));
display.append(String.format("<thead><tr><th colspan=\"4\"> Changes for Attachment %s </th></tr>", old.getFilename()));
display.append(String.format("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr></thead><tbody>", FIELD_NAME, CURRENT_VAL, DELETED_VAL, SUGGESTED_VAL));
for (Attachment._Fields field : RELEVANT_FIELDS) {
FieldMetaData fieldMetaData = Attachment.metaDataMap.get(field);
displaySimpleFieldOrSet(display, old, added, deleted, field, fieldMetaData, Release._Fields.ATTACHMENTS.getFieldName());
}
display.append("</tbody></table>");
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentAwarePortlet method doGetAttachmentForDisplay.
private void doGetAttachmentForDisplay(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
final String attachmentId = request.getParameter(PortalConstants.ATTACHMENT_ID);
final User user = UserCacheHolder.getUserFromRequest(request);
Attachment attachment = attachmentPortletUtils.getAttachmentForDisplay(user, attachmentId);
if (attachment == null) {
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "500");
} else {
writeJSON(request, response, OBJECT_MAPPER.writeValueAsString(attachment));
}
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentAwarePortlet method serveNewAttachmentId.
private void serveNewAttachmentId(ResourceRequest request, ResourceResponse response) throws IOException {
final AttachmentContent attachment = attachmentPortletUtils.createAttachmentContent(request);
if (attachment == null) {
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "404");
} else {
final String attachmentId = attachment.getId();
response.getWriter().write(attachmentId);
}
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class FossologyAwarePortlet method serveFossologyStatus.
protected void serveFossologyStatus(ResourceRequest request, ResourceResponse response) throws IOException {
DataTablesParameters parameters = DataTablesParser.parametersFrom(request);
Release release = getReleaseForFossologyStatus(request);
Map<String, FossologyStatus> fossologyStatus = getFossologyStatus(release);
JSONObject jsonResponse = JSONFactoryUtil.createJSONObject();
JSONArray data = JSONFactoryUtil.createJSONArray();
for (Map.Entry<String, FossologyStatus> entry : fossologyStatus.entrySet()) {
JSONObject row = JSONFactoryUtil.createJSONObject();
row.put("0", entry.getKey());
row.put("1", ThriftEnumUtils.enumToString(entry.getValue()));
data.put(row);
}
jsonResponse.put("attachment", getFossologyUploadableAttachment(release));
jsonResponse.put("data", data);
jsonResponse.put("draw", parameters.getDraw());
jsonResponse.put("recordsTotal", fossologyStatus.size());
jsonResponse.put("recordsFiltered", fossologyStatus.size());
writeJSON(request, response, jsonResponse);
}
Aggregations