use of org.eclipse.sw360.datahandler.thrift.components.Release in project sw360portal by sw360.
the class ComponentUploadPortlet method dealWithReleaseLinksContainedInRelease.
private void dealWithReleaseLinksContainedInRelease(Map<String, Component> componentsById, Map<String, Release> releasesById, Component component, Release release, List<Iterable<String>> csvRows) throws IOException {
final Map<String, ReleaseRelationship> releaseIdToRelationship = release.getReleaseIdToRelationship();
if (releaseIdToRelationship != null) {
for (Map.Entry<String, ReleaseRelationship> idReleaseRelationshipEntry : releaseIdToRelationship.entrySet()) {
final Release linkedRelease = releasesById.get(idReleaseRelationshipEntry.getKey());
if (linkedRelease != null) {
final ReleaseRelationship relationship = idReleaseRelationshipEntry.getValue();
final Component linkedComponent = componentsById.get(linkedRelease.getComponentId());
if (linkedComponent != null) {
printReleaseLinkEntry(component, release, linkedRelease, relationship, linkedComponent, csvRows);
}
}
}
}
}
use of org.eclipse.sw360.datahandler.thrift.components.Release 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.components.Release in project sw360portal by sw360.
the class LicenseInfoHandler method getLicenseInfoFile.
@Override
public LicenseInfoFile getLicenseInfoFile(Project project, User user, String outputGenerator, Map<String, Set<String>> releaseIdsToSelectedAttachmentIds, Map<String, Set<LicenseNameWithText>> excludedLicensesPerAttachment) throws TException {
assertNotNull(project);
assertNotNull(user);
assertNotNull(outputGenerator);
assertNotNull(releaseIdsToSelectedAttachmentIds);
assertNotNull(excludedLicensesPerAttachment);
Map<Release, Set<String>> releaseToAttachmentId = mapKeysToReleases(releaseIdsToSelectedAttachmentIds, user);
Collection<LicenseInfoParsingResult> projectLicenseInfoResults = getAllReleaseLicenseInfos(releaseToAttachmentId, user, excludedLicensesPerAttachment);
String[] outputGeneratorClassnameAndVariant = outputGenerator.split("::");
if (outputGeneratorClassnameAndVariant.length != 2) {
throw new TException("Unsupported output generator value: " + outputGenerator);
}
String outputGeneratorClassName = outputGeneratorClassnameAndVariant[0];
OutputFormatVariant outputGeneratorVariant = Enums.getIfPresent(OutputFormatVariant.class, outputGeneratorClassnameAndVariant[1]).orNull();
OutputGenerator<?> generator = getOutputGeneratorByClassnameAndVariant(outputGeneratorClassName, outputGeneratorVariant);
LicenseInfoFile licenseInfoFile = new LicenseInfoFile();
licenseInfoFile.setOutputFormatInfo(generator.getOutputFormatInfo());
String licenseInfoHeaderText = (project.isSetLicenseInfoHeaderText()) ? project.getLicenseInfoHeaderText() : getDefaultLicenseInfoHeaderText();
Object output = generator.generateOutputFile(projectLicenseInfoResults, project.getName(), project.getVersion(), licenseInfoHeaderText);
if (output instanceof byte[]) {
licenseInfoFile.setGeneratedOutput((byte[]) output);
} else if (output instanceof String) {
licenseInfoFile.setGeneratedOutput(((String) output).getBytes());
} else {
throw new TException("Unsupported output generator result: " + output.getClass().getSimpleName());
}
return licenseInfoFile;
}
use of org.eclipse.sw360.datahandler.thrift.components.Release in project sw360portal by sw360.
the class LicenseInfoHandler method getLicenseInfoForAttachment.
@Override
public List<LicenseInfoParsingResult> getLicenseInfoForAttachment(Release release, String attachmentContentId, User user) throws TException {
if (release == null) {
return Collections.singletonList(noSourceParsingResult(MSG_NO_RELEASE_GIVEN));
}
List<LicenseInfoParsingResult> cachedResults = licenseInfoCache.getIfPresent(attachmentContentId);
if (cachedResults != null) {
return cachedResults;
}
Attachment attachment = nullToEmptySet(release.getAttachments()).stream().filter(a -> a.getAttachmentContentId().equals(attachmentContentId)).findFirst().orElseThrow(() -> {
String message = String.format("Attachment selected for license info generation is not found in release's attachments. Release id: %s. Attachment content id: %s", release.getId(), attachmentContentId);
return new IllegalStateException(message);
});
try {
List<LicenseInfoParser> applicableParsers = parsers.stream().filter(parser -> wrapTException(() -> parser.isApplicableTo(attachment, user, release))).collect(Collectors.toList());
if (applicableParsers.size() == 0) {
LOGGER.warn("No applicable parser has been found for the attachment selected for license information");
return assignReleaseToLicenseInfoParsingResult(assignFileNameToLicenseInfoParsingResult(noSourceParsingResult("No applicable parser has been found for the attachment"), attachment.getFilename()), release);
} else if (applicableParsers.size() > 1) {
LOGGER.info("More than one parser claims to be able to parse attachment with contend id " + attachmentContentId);
}
List<LicenseInfoParsingResult> results = applicableParsers.stream().map(parser -> wrapTException(() -> parser.getLicenseInfos(attachment, user, release))).flatMap(Collection::stream).collect(Collectors.toList());
filterEmptyLicenses(results);
results = assignReleaseToLicenseInfoParsingResults(results, release);
licenseInfoCache.put(attachmentContentId, results);
return results;
} catch (WrappedTException exception) {
throw exception.getCause();
}
}
use of org.eclipse.sw360.datahandler.thrift.components.Release in project sw360portal by sw360.
the class LicenseDatabaseHandler method checkIfInUse.
public boolean checkIfInUse(String licenseId) {
ReleaseRepository releaseRepository = new ReleaseRepository(db, new VendorRepository(db));
final List<Release> usingReleases = releaseRepository.searchReleasesByUsingLicenseId(licenseId);
return !usingReleases.isEmpty();
}
Aggregations