use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.
the class ProjectController method downloadLicenseInfo.
@RequestMapping(value = PROJECTS_URL + "/{id}/licenseinfo", method = RequestMethod.GET)
public void downloadLicenseInfo(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication, @RequestParam("generatorClassName") String generatorClassName, HttpServletResponse response) throws TException, IOException {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
final Project sw360Project = projectService.getProjectForUserById(id, sw360User);
final Map<String, Set<String>> selectedReleaseAndAttachmentIds = new HashMap<>();
for (final String releaseId : sw360Project.getReleaseIdToUsage().keySet()) {
final Release release = releaseService.getReleaseForUserById(releaseId, sw360User);
if (release.isSetAttachments()) {
if (!selectedReleaseAndAttachmentIds.containsKey(releaseId)) {
selectedReleaseAndAttachmentIds.put(releaseId, new HashSet<>());
}
final Set<Attachment> attachments = release.getAttachments();
for (final Attachment attachment : attachments) {
selectedReleaseAndAttachmentIds.get(releaseId).add(attachment.getAttachmentContentId());
}
}
}
// TODO: implement method to determine excluded licenses
final Map<String, Set<LicenseNameWithText>> excludedLicenses = new HashMap<>();
final String projectName = sw360Project.getName();
final String timestamp = SW360Utils.getCreatedOn();
final OutputFormatInfo outputFormatInfo = licenseInfoService.getOutputFormatInfoForGeneratorClass(generatorClassName);
final String filename = String.format("LicenseInfo-%s-%s.%s", projectName, timestamp, outputFormatInfo.getFileExtension());
final LicenseInfoFile licenseInfoFile = licenseInfoService.getLicenseInfoFile(sw360Project, sw360User, generatorClassName, selectedReleaseAndAttachmentIds, excludedLicenses);
byte[] byteContent = licenseInfoFile.bufferForGeneratedOutput().array();
response.setContentType(outputFormatInfo.getMimeType());
response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", filename));
FileCopyUtils.copy(byteContent, response.getOutputStream());
}
use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.
the class Sw360AttachmentService method uploadAttachment.
public Attachment uploadAttachment(MultipartFile file, Attachment newAttachment, User sw360User) throws IOException, TException {
// TODO: shouldn't the fileName be taken from newAttachment?
String fileName = file.getOriginalFilename();
String contentType = file.getContentType();
final AttachmentContent attachmentContent = makeAttachmentContent(fileName, contentType);
final AttachmentConnector attachmentConnector = getConnector();
Attachment attachment = new AttachmentFrontendUtils().uploadAttachmentContent(attachmentContent, file.getInputStream(), sw360User);
attachment.setSha1(attachmentConnector.getSha1FromAttachmentContentId(attachmentContent.getId()));
AttachmentType attachmentType = newAttachment.getAttachmentType();
if (attachmentType != null) {
attachment.setAttachmentType(attachmentType);
}
CheckStatus checkStatus = newAttachment.getCheckStatus();
if (checkStatus != null) {
attachment.setCheckStatus(checkStatus);
}
return attachment;
}
use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.
the class CompareTodos method renderTodoRow.
private static void renderTodoRow(StringBuilder display, Todo todo) {
display.append("<tr>");
for (Todo._Fields field : RELEVANT_FIELDS) {
FieldMetaData fieldMetaData = Todo.metaDataMap.get(field);
Object fieldValue = todo.getFieldValue(field);
if (field.equals(Todo._Fields.OBLIGATIONS) && fieldValue != null) {
fieldValue = ((List<Obligation>) fieldValue).stream().map(Obligation::getName).collect(Collectors.toList());
}
display.append(String.format("<td>%s</td>", getDisplayString(fieldMetaData.valueMetaData.type, fieldValue)));
}
display.append("</tr>");
}
use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.
the class LicensesPortlet method prepareDetailView.
private void prepareDetailView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
String id = request.getParameter(LICENSE_ID);
User user = UserCacheHolder.getUserFromRequest(request);
request.setAttribute(IS_USER_AT_LEAST_CLEARING_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user) ? "Yes" : "No");
if (id != null) {
try {
LicenseService.Iface client = thriftClients.makeLicenseClient();
License moderationLicense = client.getByIDWithOwnModerationRequests(id, user.getDepartment(), user);
List<Todo> allTodos = nullToEmptyList(moderationLicense.getTodos());
List<Todo> addedTodos = allTodos.stream().filter(CommonUtils::isTemporaryTodo).collect(Collectors.toList());
List<Todo> currentTodos = allTodos.stream().filter(t -> !CommonUtils.isTemporaryTodo(t)).collect(Collectors.toList());
request.setAttribute(ADDED_TODOS_FROM_MODERATION_REQUEST, addedTodos);
request.setAttribute(DB_TODOS_FROM_MODERATION_REQUEST, currentTodos);
request.setAttribute(MODERATION_LICENSE_DETAIL, moderationLicense);
License dbLicense = client.getByID(id, user.getDepartment());
request.setAttribute(KEY_LICENSE_DETAIL, dbLicense);
List<Obligation> obligations = client.getObligations();
request.setAttribute(KEY_OBLIGATION_LIST, obligations);
addLicenseBreadcrumb(request, response, moderationLicense);
} catch (TException e) {
log.error("Error fetching license details from backend", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_LICENSE);
}
}
}
use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.
the class LicenseModerationRequestGenerator method setAdditionsAndDeletions.
@Override
public ModerationRequest setAdditionsAndDeletions(ModerationRequest request, License updateLicense, License actualLicense) {
updateDocument = updateLicense;
actualDocument = actualLicense;
documentAdditions = new License();
documentDeletions = new License();
// required fields:
documentAdditions.setFullname(updateLicense.getFullname());
documentAdditions.setId(actualLicense.getId());
documentDeletions.setFullname(actualLicense.getFullname());
documentDeletions.setId(actualLicense.getId());
Map<String, Todo> actualTodos = Maps.uniqueIndex(nullToEmptyList(actualLicense.getTodos()), Todo::getId);
for (Todo updateTodo : updateLicense.getTodos()) {
if (!actualTodos.containsKey(updateTodo.getId())) {
if (!documentAdditions.isSetTodos()) {
documentAdditions.setTodos(new ArrayList<>());
}
documentAdditions.getTodos().add(updateTodo);
} else {
Todo actualTodo = actualTodos.get(updateTodo.getId());
Set<String> actualWhitelist = actualTodo.whitelist != null ? actualTodo.whitelist : new HashSet<String>();
Set<String> updateWhitelist = updateTodo.whitelist != null ? updateTodo.whitelist : new HashSet<String>();
String departement = request.getRequestingUserDepartment();
if (updateWhitelist.contains(departement) && !actualWhitelist.contains(departement)) {
if (!documentAdditions.isSetTodos()) {
documentAdditions.setTodos(new ArrayList<>());
}
documentAdditions.getTodos().add(updateTodo);
} else if (!updateWhitelist.contains(departement) && actualWhitelist.contains(departement)) {
if (!documentDeletions.isSetTodos()) {
documentDeletions.setTodos(new ArrayList<>());
}
documentDeletions.getTodos().add(actualTodo);
}
}
}
request.setLicenseAdditions(documentAdditions);
request.setLicenseDeletions(documentDeletions);
return request;
}
Aggregations