use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ReleaseHelper method addFieldValueToRow.
private void addFieldValueToRow(List<String> row, Release._Fields field, Release release) throws SW360Exception {
switch(field) {
case COMPONENT_ID:
// first, add data for given field
row.add(release.getComponentId());
// second, add joined data, remark that headers have already been added
// accordingly
// add component type in every case
Component component = this.preloadedComponents.get(release.componentId);
if (component == null) {
// maybe cache was not initialized properly, so try to load manually
try {
component = cClient.getComponentById(release.getComponentId(), user);
} catch (TException e) {
log.warn("No component found for id " + release.getComponentId() + " which is set in release with id " + release.getId(), e);
component = null;
}
}
// check again and add value
if (component == null) {
row.add("");
} else {
row.add(ThriftEnumUtils.enumToString(component.getComponentType()));
}
// and project origin only if wanted
if (addAdditionalData()) {
if (releaseClearingStatusDataByRelease.containsKey(release)) {
row.add(releaseClearingStatusDataByRelease.get(release).getProjectNames());
} else {
row.add("");
}
}
break;
case VENDOR:
addVendorToRow(release.getVendor(), row);
break;
case COTS_DETAILS:
addCotsDetailsToRow(release.getCotsDetails(), row);
break;
case CLEARING_INFORMATION:
addClearingInformationToRow(release.getClearingInformation(), row);
break;
case ECC_INFORMATION:
addEccInformationToRow(release.getEccInformation(), row);
break;
case RELEASE_ID_TO_RELATIONSHIP:
addReleaseIdToRelationShipToRow(release.getReleaseIdToRelationship(), row);
break;
case ATTACHMENTS:
String size = Integer.toString(release.isSetAttachments() ? release.getAttachments().size() : 0);
row.add(size);
break;
default:
Object fieldValue = release.getFieldValue(field);
row.add(fieldValueAsString(fieldValue));
}
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ReleaseHelper method batchloadComponents.
private void batchloadComponents(Set<String> cIds) throws SW360Exception {
try {
List<Component> componentsShort = cClient.getComponentsShort(cIds);
this.preloadedComponents.putAll(ThriftUtils.getIdMap(componentsShort));
} catch (TException e) {
throw new SW360Exception("Could not get Components for ids [" + cIds + "] because of:\n" + e.getMessage());
}
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class AttachmentStreamConnector method getAttachmentBundleStream.
/**
* It is highly recommended to close this stream after using to avoid connection leak
*/
public <T> InputStream getAttachmentBundleStream(Set<AttachmentContent> attachments, User user, T context) throws IOException, SW360Exception {
assertNotNull(context);
PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream(in);
new Thread(() -> {
byte[] buffer = new byte[1024];
int length;
try (ZipOutputStream zip = new ZipOutputStream(out)) {
for (AttachmentContent attachment : attachments) {
// TODO: handle attachments with equal name
ZipEntry zipEntry = new ZipEntry(attachment.getFilename());
zip.putNextEntry(zipEntry);
try (InputStream attachmentStream = getAttachmentStream(attachment, user, context)) {
while ((length = attachmentStream.read(buffer)) >= 0) {
zip.write(buffer, 0, length);
}
} catch (TException e) {
log.error("failed to get AttachmentStream, maybe due to permission problems", e);
}
zip.closeEntry();
}
} catch (IOException e) {
log.error("failed to write zip stream", e);
}
}).start();
return in;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ComponentDatabaseHandlerTest method addRelease.
private String addRelease(String componentId, Set<String> licenseIds) throws SW360Exception {
Release release = new Release().setName("REL").setVersion(nextReleaseVersion + "").setMainLicenseIds(licenseIds).setComponentId(componentId);
nextReleaseVersion++;
String id = handler.addRelease(release, user1.getEmail()).getId();
assertNotNull(id);
return id;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ProjectDatabaseHandler method getProjectById.
// //////////////////////////
// GET INDIVIDUAL OBJECTS //
// //////////////////////////
public Project getProjectById(String id, User user) throws SW360Exception {
Project project = repository.get(id);
assertNotNull(project);
if (!makePermission(project, user).isActionAllowed(RequestedAction.READ)) {
throw fail("User " + user + " is not allowed to view the requested project " + project + "!");
}
return project;
}
Aggregations