Search in sources :

Example 56 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields 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;
}
Also used : ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 57 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class ProjectModerationRequestGenerator method setAdditionsAndDeletions.

@Override
public ModerationRequest setAdditionsAndDeletions(ModerationRequest request, Project updateProject, Project actualProject) {
    updateDocument = updateProject;
    actualDocument = actualProject;
    documentAdditions = new Project();
    documentDeletions = new Project();
    // required fields:
    documentAdditions.setName(updateProject.getName());
    documentAdditions.setId(actualProject.getId());
    documentDeletions.setName(actualProject.getName());
    documentDeletions.setId(actualProject.getId());
    for (Project._Fields field : Project._Fields.values()) {
        if (Project.metaDataMap.get(field).valueMetaData.type == TType.BOOL || Project.metaDataMap.get(field).valueMetaData.type == TType.I32) {
            if (actualDocument.getFieldValue(field) != updateDocument.getFieldValue(field)) {
                documentAdditions.setFieldValue(field, updateDocument.getFieldValue(field));
                documentDeletions.setFieldValue(field, actualDocument.getFieldValue(field));
            }
        } else if (actualProject.getFieldValue(field) == null) {
            documentAdditions.setFieldValue(field, updateProject.getFieldValue(field));
        } else if (updateProject.getFieldValue(field) == null) {
            documentDeletions.setFieldValue(field, actualProject.getFieldValue(field));
        } else if (!actualProject.getFieldValue(field).equals(updateProject.getFieldValue(field))) {
            switch(field) {
                // ignored fields and concluded fields
                case PERMISSIONS:
                case DOCUMENT_STATE:
                case RELEASE_CLEARING_STATE_SUMMARY:
                    break;
                case ATTACHMENTS:
                    dealWithAttachments(Project._Fields.ATTACHMENTS);
                    break;
                case LINKED_PROJECTS:
                    dealWithEnumMap(Project._Fields.LINKED_PROJECTS, ProjectRelationship.class);
                    break;
                case RELEASE_ID_TO_USAGE:
                    dealWithStringKeyedMap(Project._Fields.RELEASE_ID_TO_USAGE);
                    break;
                case ROLES:
                    dealWithCustomMap(Project._Fields.ROLES);
                    break;
                default:
                    dealWithBaseTypes(field, Project.metaDataMap.get(field));
            }
        }
    }
    request.setProjectAdditions(documentAdditions);
    request.setProjectDeletions(documentDeletions);
    return request;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)

Example 58 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields 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;
}
Also used : WrappedException.wrapTException(org.eclipse.sw360.datahandler.common.WrappedException.wrapTException) TException(org.apache.thrift.TException) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) CommonUtils.nullToEmptySet(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptySet) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 59 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields 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();
    }
}
Also used : org.eclipse.sw360.licenseinfo.parsers(org.eclipse.sw360.licenseinfo.parsers) java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) Release(org.eclipse.sw360.datahandler.thrift.components.Release) AttachmentDatabaseHandler(org.eclipse.sw360.attachments.db.AttachmentDatabaseHandler) LicenseNameWithTextUtils(org.eclipse.sw360.licenseinfo.util.LicenseNameWithTextUtils) Enums(com.google.common.base.Enums) Logger(org.apache.log4j.Logger) Lists(com.google.common.collect.Lists) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) org.eclipse.sw360.licenseinfo.outputGenerators(org.eclipse.sw360.licenseinfo.outputGenerators) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) WrappedException.wrapTException(org.eclipse.sw360.datahandler.common.WrappedException.wrapTException) MalformedURLException(java.net.MalformedURLException) TException(org.apache.thrift.TException) ComponentDatabaseHandler(org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) REPORT(org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatVariant.REPORT) DISCLOSURE(org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatVariant.DISCLOSURE) Sets(com.google.common.collect.Sets) DatabaseSettings(org.eclipse.sw360.datahandler.common.DatabaseSettings) TimeUnit(java.util.concurrent.TimeUnit) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) Entry(java.util.Map.Entry) org.eclipse.sw360.datahandler.thrift.licenseinfo(org.eclipse.sw360.datahandler.thrift.licenseinfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) SW360Assert.assertNotNull(org.eclipse.sw360.datahandler.common.SW360Assert.assertNotNull) CommonUtils.nullToEmptySet(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptySet) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Example 60 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields 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();
}
Also used : VendorRepository(org.eclipse.sw360.datahandler.db.VendorRepository) ReleaseRepository(org.eclipse.sw360.datahandler.db.ReleaseRepository) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

Release (org.eclipse.sw360.datahandler.thrift.components.Release)93 User (org.eclipse.sw360.datahandler.thrift.users.User)42 TException (org.apache.thrift.TException)38 Test (org.junit.Test)23 Component (org.eclipse.sw360.datahandler.thrift.components.Component)20 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)20 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)17 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)13 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)13 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)12 FieldMetaData (org.apache.thrift.meta_data.FieldMetaData)11 FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)11 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)10 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)9 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)7 Before (org.junit.Before)7 Collectors (java.util.stream.Collectors)6 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)6 FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)6 IOException (java.io.IOException)5