use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class VendorDatabaseHandler method deleteVendor.
public RequestStatus deleteVendor(String id, User user) throws SW360Exception {
Vendor vendor = repository.get(id);
assertNotNull(vendor);
if (makePermission(vendor, user).isActionAllowed(RequestedAction.DELETE)) {
repository.remove(id);
return RequestStatus.SUCCESS;
} else {
log.error("User is not allowed to delete!");
return RequestStatus.FAILURE;
}
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class FossologySshConnectorTest method testRunInFossologyViaSshReturnErrorOnTimeout.
@Test
public void testRunInFossologyViaSshReturnErrorOnTimeout() throws Exception {
doThrow(new SW360Exception()).when(fossologySshConnector).waitCompletion(channel, executionTimeout);
final int exitCode = fossologySshConnector.runInFossologyViaSsh("cmd");
assertThat(exitCode, lessThan(0));
verify(jSchSessionProvider).getSession(connectionTimeout);
verify(jSchSessionProvider).getServerString();
// isConnected is mocked: it is disconnected twice
verify(channel, atLeastOnce()).disconnect();
// isConnected is mocked: it is disconnected twice
verify(jSchSessionProvider, atLeastOnce()).closeSession(session);
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class AbstractCLIParser method hasThisXMLRootElement.
protected <T> boolean hasThisXMLRootElement(AttachmentContent content, String rootElementNamespace, String rootElementName, User user, T context) throws TException {
XMLInputFactory xmlif = XMLInputFactory.newFactory();
XMLStreamReader xmlStreamReader = null;
InputStream attachmentStream = null;
try {
attachmentStream = attachmentConnector.getAttachmentStream(content, user, context);
xmlStreamReader = xmlif.createXMLStreamReader(attachmentStream);
// skip to first element
while (xmlStreamReader.hasNext() && xmlStreamReader.next() != XMLStreamConstants.START_ELEMENT) ;
xmlStreamReader.require(XMLStreamConstants.START_ELEMENT, rootElementNamespace, rootElementName);
return true;
} catch (XMLStreamException | SW360Exception e) {
return false;
} finally {
if (null != xmlStreamReader) {
try {
xmlStreamReader.close();
} catch (XMLStreamException e) {
// ignore it
}
}
closeQuietly(attachmentStream, log);
}
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class CLIParser method getLicenseInfos.
@Override
public <T> List<LicenseInfoParsingResult> getLicenseInfos(Attachment attachment, User user, T context) throws TException {
AttachmentContent attachmentContent = attachmentContentProvider.getAttachmentContent(attachment);
LicenseInfo licenseInfo = new LicenseInfo().setFilenames(Arrays.asList(attachmentContent.getFilename()));
LicenseInfoParsingResult result = new LicenseInfoParsingResult().setLicenseInfo(licenseInfo);
InputStream attachmentStream = null;
try {
attachmentStream = attachmentConnector.getAttachmentStream(attachmentContent, user, context);
Document doc = getDocument(attachmentStream);
Set<String> copyrights = getCopyrights(doc);
licenseInfo.setCopyrights(copyrights);
Set<LicenseNameWithText> licenseNamesWithTexts = getLicenseNameWithTexts(doc);
licenseInfo.setLicenseNamesWithTexts(licenseNamesWithTexts);
result.setStatus(LicenseInfoRequestStatus.SUCCESS);
} catch (ParserConfigurationException | IOException | XPathExpressionException | SAXException | SW360Exception e) {
log.error(e);
result.setStatus(LicenseInfoRequestStatus.FAILURE).setMessage("Error while parsing CLI file: " + e.toString());
} finally {
closeQuietly(attachmentStream, log);
}
return Collections.singletonList(result);
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class LicenseDatabaseHandler method updateLicenseFromInputLicense.
private License updateLicenseFromInputLicense(License license, License inputLicense, String businessUnit, User user) {
if (inputLicense.isSetTodos()) {
for (Todo todo : inputLicense.getTodos()) {
if (isTemporaryTodo(todo)) {
todo.unsetId();
try {
String todoDatabaseId = addTodo(todo, user);
license.addToTodoDatabaseIds(todoDatabaseId);
} catch (SW360Exception e) {
log.error("Error adding todo to database.");
}
} else if (todo.isSetId()) {
Todo dbTodo = todoRepository.get(todo.id);
if (todo.whitelist.contains(businessUnit) && !dbTodo.whitelist.contains(businessUnit)) {
dbTodo.addToWhitelist(businessUnit);
todoRepository.update(dbTodo);
}
if (!todo.whitelist.contains(businessUnit) && dbTodo.whitelist.contains(businessUnit)) {
dbTodo.whitelist.remove(businessUnit);
todoRepository.update(dbTodo);
}
}
}
}
license.setText(inputLicense.getText());
license.setFullname(inputLicense.getFullname());
// only a new license gets its id from the shortname. Id of an existing license isn't supposed to be changed anyway
if (!license.isSetId())
license.setId(inputLicense.getShortname());
license.unsetShortname();
license.setLicenseTypeDatabaseId(inputLicense.getLicenseTypeDatabaseId());
license.unsetLicenseType();
license.setGPLv2Compat(Optional.ofNullable(inputLicense.getGPLv2Compat()).orElse(Ternary.UNDEFINED));
license.setGPLv3Compat(Optional.ofNullable(inputLicense.getGPLv3Compat()).orElse(Ternary.UNDEFINED));
license.setExternalLicenseLink(inputLicense.getExternalLicenseLink());
return license;
}
Aggregations