use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ComponentPortlet method exportExcel.
private void exportExcel(ResourceRequest request, ResourceResponse response) {
final User user = UserCacheHolder.getUserFromRequest(request);
try {
boolean extendedByReleases = Boolean.valueOf(request.getParameter(PortalConstants.EXTENDED_EXCEL_EXPORT));
List<Component> components = getFilteredComponentList(request);
ComponentExporter exporter = new ComponentExporter(thriftClients.makeComponentClient(), components, user, extendedByReleases);
PortletResponseUtil.sendFile(request, response, "Components.xlsx", exporter.makeExcelExport(components), CONTENT_TYPE_OPENXML_SPREADSHEET);
} catch (IOException | SW360Exception e) {
log.error("An error occurred while generating the Excel export", e);
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
}
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ModerationDatabaseHandler method createRequest.
public RequestStatus createRequest(Component component, User user, Boolean isDeleteRequest) {
Component dbcomponent;
try {
dbcomponent = componentDatabaseHandler.getComponent(component.getId(), user);
} catch (SW360Exception e) {
log.error("Could not get original component from database. Could not generate moderation request.", e);
return RequestStatus.FAILURE;
}
// Define moderators
Set<String> moderators = new HashSet<>();
CommonUtils.add(moderators, dbcomponent.getCreatedBy());
try {
String department = getDepartmentByUserEmail(component.getCreatedBy());
CommonUtils.addAll(moderators, getUsersAtLeast(UserGroup.CLEARING_ADMIN, department));
} catch (TException e) {
log.error("Could not get user from database. Clearing admins not added as moderators, since department is missing.");
}
CommonUtils.addAll(moderators, getUsersAtLeast(UserGroup.ADMIN));
ModerationRequest request = createStubRequest(user, isDeleteRequest, component.getId(), moderators);
// Set meta-data
request.setDocumentType(DocumentType.COMPONENT);
request.setDocumentName(SW360Utils.printName(dbcomponent));
// Fill the request
ModerationRequestGenerator generator = new ComponentModerationRequestGenerator();
request = generator.setAdditionsAndDeletions(request, component, dbcomponent);
if (component.isSetComponentType()) {
request.setComponentType(component.getComponentType());
}
addOrUpdate(request, user);
return RequestStatus.SENT_TO_MODERATOR;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ModerationDatabaseHandler method createRequest.
public RequestStatus createRequest(Release release, User user, Boolean isDeleteRequest, Function<Release, Set<String>> moderatorsProvider) {
Release dbrelease;
try {
dbrelease = componentDatabaseHandler.getRelease(release.getId(), user);
} catch (SW360Exception e) {
log.error("Could not get original release from database. Could not generate moderation request.", e);
return RequestStatus.FAILURE;
}
Set<String> moderators = moderatorsProvider.apply(dbrelease);
ModerationRequest request = createStubRequest(user, isDeleteRequest, release.getId(), moderators);
// Set meta-data
request.setDocumentType(DocumentType.RELEASE);
request.setDocumentName(SW360Utils.printName(dbrelease));
// Fill the rest
SW360Utils.setVendorId(release);
SW360Utils.setVendorId(dbrelease);
ModerationRequestGenerator generator = new ReleaseModerationRequestGenerator();
request = generator.setAdditionsAndDeletions(request, release, dbrelease);
try {
Component parentComponent = componentDatabaseHandler.getComponent(release.getComponentId(), user);
request.setComponentType(parentComponent.getComponentType());
} catch (SW360Exception e) {
log.error("Could not retrieve parent component type of release with ID=" + release.getId());
}
addOrUpdate(request, user);
return RequestStatus.SENT_TO_MODERATOR;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ModerationDatabaseHandler method createRequest.
public RequestStatus createRequest(License license, User user) {
License dblicense;
try {
dblicense = licenseDatabaseHandler.getLicenseForOrganisation(license.getId(), user.getDepartment());
} catch (SW360Exception e) {
log.error("Could not get original license from database. Could not generate moderation request.", e);
return RequestStatus.FAILURE;
}
// Define moderators
Set<String> moderators = getLicenseModerators(user.getDepartment());
ModerationRequest request = createStubRequest(user, false, license.getId(), moderators);
// Set meta-data
request.setDocumentType(DocumentType.LICENSE);
request.setDocumentName(SW360Utils.printName(license));
// Fill the request
ModerationRequestGenerator generator = new LicenseModerationRequestGenerator();
request = generator.setAdditionsAndDeletions(request, license, dblicense);
addOrUpdate(request, user);
return RequestStatus.SENT_TO_MODERATOR;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class RemoteAttachmentDownloader method retrieveRemoteAttachments.
public static int retrieveRemoteAttachments(Supplier<HttpClient> httpClient, String dbAttachments, Duration downloadTimeout) throws MalformedURLException {
AttachmentConnector attachmentConnector = new AttachmentConnector(httpClient, dbAttachments, downloadTimeout);
AttachmentRepository attachmentRepository = new AttachmentRepository(new DatabaseConnector(httpClient, dbAttachments));
List<AttachmentContent> remoteAttachments = attachmentRepository.getOnlyRemoteAttachments();
log.info(format("we have %d remote attachments to retrieve", remoteAttachments.size()));
int count = 0;
for (AttachmentContent attachmentContent : remoteAttachments) {
if (!attachmentContent.isOnlyRemote()) {
log.info(format("skipping attachment (%s), which should already be available", attachmentContent.getId()));
continue;
}
String attachmentContentId = attachmentContent.getId();
log.info(format("retrieving attachment (%s) {filename=%s}", attachmentContentId, attachmentContent.getFilename()));
log.debug("url is " + attachmentContent.getRemoteUrl());
InputStream content = null;
try {
content = attachmentConnector.unsafeGetAttachmentStream(attachmentContent);
if (content == null) {
log.error("null content retrieving attachment " + attachmentContentId);
continue;
}
try {
long length = length(content);
log.info(format("retrieved attachment (%s), it was %d bytes long", attachmentContentId, length));
count++;
} catch (IOException e) {
log.error("attachment was downloaded but somehow not available in database " + attachmentContentId, e);
}
} catch (SW360Exception e) {
log.error("cannot retrieve attachment " + attachmentContentId, e);
} finally {
closeQuietly(content, log);
}
}
return count;
}
Aggregations