use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class FossologyScriptsHandler method deployScripts.
public RequestStatus deployScripts() throws SW360Exception {
RequestStatus status = RequestStatus.SUCCESS;
for (String scriptFileName : SCRIPT_FILE_NAMES) {
final InputStream inputStream = FossologyScriptsHandler.class.getResourceAsStream(SCRIPTS_FOLDER + scriptFileName);
if (inputStream == null) {
log.error("cannot get content of script " + scriptFileName);
status = RequestStatus.FAILURE;
continue;
}
try {
if (!fossologyUploader.copyToFossology(scriptFileName, inputStream, true)) {
status = RequestStatus.FAILURE;
}
} finally {
closeQuietly(inputStream, log);
}
}
return status;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ModerationDatabaseHandler method createRequest.
public RequestStatus createRequest(Project project, User user, Boolean isDeleteRequest) {
Project dbproject;
try {
dbproject = projectDatabaseHandler.getProjectById(project.getId(), user);
} catch (SW360Exception e) {
log.error("Could not get original project from database. Could not generate moderation request.", e);
return RequestStatus.FAILURE;
}
// Define moderators
Set<String> moderators = getProjectModerators(dbproject);
ModerationRequest request = createStubRequest(user, isDeleteRequest, project.getId(), moderators);
// Set meta-data
request.setDocumentType(DocumentType.PROJECT);
request.setDocumentName(SW360Utils.printName(dbproject));
// Fill the request
ModerationRequestGenerator generator = new ProjectModerationRequestGenerator();
request = generator.setAdditionsAndDeletions(request, project, dbproject);
addOrUpdate(request, user);
return RequestStatus.SENT_TO_MODERATOR;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ComponentImportUtilsTest method testImportOnEmptyDb.
@Test
public void testImportOnEmptyDb() throws Exception {
FluentIterable<ComponentCSVRecord> compCSVRecords = getCompCSVRecordsFromTestFile(fileName);
assertThat(componentClient.getComponentSummary(user), is(empty()));
assertThat(componentClient.getReleaseSummary(user), is(empty()));
ComponentImportUtils.writeToDatabase(compCSVRecords, componentClient, vendorClient, attachmentClient, user);
assertExpectedComponentsInDb();
final String attachmentContentId = getCreatedAttachmentContentId();
final AttachmentContent overwriter = new AttachmentContent().setId(OVERRIDING_ID).setOnlyRemote(true).setRemoteUrl(REMOTE_URL).setType(TYPE_ATTACHMENT);
final AttachmentContent addition = new AttachmentContent().setId(ADDITIONAL_ID).setOnlyRemote(true).setRemoteUrl(REMOTE_URL).setType(TYPE_ATTACHMENT);
attachmentRepository.add(overwriter);
attachmentRepository.add(addition);
assertThat(attachmentRepository.getAll(), Matchers.hasSize(3));
FluentIterable<ComponentAttachmentCSVRecord> compAttachmentCSVRecords = getCompAttachmentCSVRecordsFromTestFile(attachmentsFilename);
ComponentImportUtils.writeAttachmentsToDatabase(compAttachmentCSVRecords, user, componentClient, attachmentClient);
try {
attachmentClient.getAttachmentContent(attachmentContentId);
fail("Expected exception not thrown");
} catch (Exception e) {
assertThat(e, is(instanceOf(SW360Exception.class)));
assertThat(((SW360Exception) e).getWhy(), is("Cannot find " + attachmentContentId + " in database."));
}
assertThat(attachmentRepository.getAll(), Matchers.hasSize(2));
final AttachmentContent attachmentContent = attachmentClient.getAttachmentContent(getCreatedAttachmentContentId());
assertThat(attachmentContent, is(overwriter));
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ReleaseHelper method getReleases.
List<Release> getReleases(Set<String> ids) throws SW360Exception {
if (preloadedLinkedReleases != null) {
return getPreloadedReleases(ids);
}
List<Release> releasesByIdsForExport;
try {
releasesByIdsForExport = cClient.getReleasesByIdsForExport(nullToEmptySet(ids));
} catch (TException e) {
throw new SW360Exception("Error fetching release information");
}
// update preload cache so that it is available on next call to this method
setPreloadedLinkedReleases(ThriftUtils.getIdMap(releasesByIdsForExport), false);
return releasesByIdsForExport;
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class AttachmentStreamConnector method downloadRemoteAttachmentAndUpdate.
private AttachmentContent downloadRemoteAttachmentAndUpdate(AttachmentContent attachmentContent) throws SW360Exception {
final InputStream downloadStream;
try {
downloadStream = attachmentContentDownloader.download(attachmentContent, downloadTimeout);
} catch (IOException e) {
String msg = "Cannot download attachment " + attachmentContent.getId() + " from URL";
log.error(msg, e);
throw new SW360Exception(msg);
}
uploadAttachment(attachmentContent, downloadStream);
attachmentContent = connector.get(AttachmentContent.class, attachmentContent.getId());
attachmentContent.setOnlyRemote(false);
connector.update(attachmentContent);
return attachmentContent;
}
Aggregations