Search in sources :

Example 51 with Release._Fields

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

the class FossologyAwarePortlet method serveFossologyStatus.

protected void serveFossologyStatus(ResourceRequest request, ResourceResponse response) throws IOException {
    DataTablesParameters parameters = DataTablesParser.parametersFrom(request);
    Release release = getReleaseForFossologyStatus(request);
    Map<String, FossologyStatus> fossologyStatus = getFossologyStatus(release);
    JSONObject jsonResponse = JSONFactoryUtil.createJSONObject();
    JSONArray data = JSONFactoryUtil.createJSONArray();
    for (Map.Entry<String, FossologyStatus> entry : fossologyStatus.entrySet()) {
        JSONObject row = JSONFactoryUtil.createJSONObject();
        row.put("0", entry.getKey());
        row.put("1", ThriftEnumUtils.enumToString(entry.getValue()));
        data.put(row);
    }
    jsonResponse.put("attachment", getFossologyUploadableAttachment(release));
    jsonResponse.put("data", data);
    jsonResponse.put("draw", parameters.getDraw());
    jsonResponse.put("recordsTotal", fossologyStatus.size());
    jsonResponse.put("recordsFiltered", fossologyStatus.size());
    writeJSON(request, response, jsonResponse);
}
Also used : DataTablesParameters(org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) CommonUtils.nullToEmptyMap(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 52 with Release._Fields

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

the class FossologyAwarePortlet method getReleaseForFossologyStatus.

protected Release getReleaseForFossologyStatus(ResourceRequest request) {
    String releaseId = request.getParameter(RELEASE_ID);
    String clearingTeam = request.getParameter(CLEARING_TEAM);
    boolean cached = Boolean.parseBoolean(request.getParameter("cached"));
    if (!isNullOrEmpty(releaseId) && !isNullOrEmpty(clearingTeam)) {
        try {
            final Release release;
            if (!cached) {
                FossologyService.Iface client = thriftClients.makeFossologyClient();
                release = client.getStatusInFossology(releaseId, UserCacheHolder.getUserFromRequest(request), clearingTeam);
            } else {
                ComponentService.Iface client = thriftClients.makeComponentClient();
                release = client.getReleaseById(releaseId, UserCacheHolder.getUserFromRequest(request));
            }
            if (release != null) {
                return release;
            } else {
                log.error("no response from backend!");
            }
        } catch (TException e) {
            log.error("Could not release status in fossology", e);
        }
    }
    log.error("Could not get release from request");
    return null;
}
Also used : TException(org.apache.thrift.TException) FossologyService(org.eclipse.sw360.datahandler.thrift.fossology.FossologyService) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 53 with Release._Fields

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

Example 54 with Release._Fields

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

the class COTSDetailsModerationRequestGenerator method setAdditionsAndDeletions.

@Override
public ModerationRequest setAdditionsAndDeletions(ModerationRequest request, COTSDetails update, COTSDetails actual) {
    updateDocument = update == null ? new COTSDetails() : update;
    actualDocument = actual == null ? new COTSDetails() : actual;
    documentAdditions = null;
    documentDeletions = null;
    for (COTSDetails._Fields field : COTSDetails._Fields.values()) {
        if (COTSDetails.metaDataMap.get(field).valueMetaData.type == TType.BOOL || COTSDetails.metaDataMap.get(field).valueMetaData.type == TType.I32) {
            if (actualDocument.getFieldValue(field) != updateDocument.getFieldValue(field)) {
                if (documentAdditions == null) {
                    documentAdditions = new COTSDetails();
                }
                if (documentDeletions == null) {
                    documentDeletions = new COTSDetails();
                }
                documentAdditions.setFieldValue(field, updateDocument.getFieldValue(field));
                documentDeletions.setFieldValue(field, actualDocument.getFieldValue(field));
            }
            continue;
        }
        if (COTSDetails.metaDataMap.get(field).valueMetaData.type == TType.STRING) {
            if (isNullOrEmpty((String) actualDocument.getFieldValue(field)) && isNullOrEmpty((String) updateDocument.getFieldValue(field))) {
                continue;
            }
            if (actualDocument.isSet(field) && !updateDocument.isSet(field)) {
                if (documentDeletions == null) {
                    documentDeletions = new COTSDetails();
                }
                documentDeletions.setFieldValue(field, actualDocument.getFieldValue(field));
                continue;
            }
            if (updateDocument.isSet(field) && !actualDocument.isSet(field)) {
                if (documentAdditions == null) {
                    documentAdditions = new COTSDetails();
                }
                documentAdditions.setFieldValue(field, updateDocument.getFieldValue(field));
                continue;
            }
            if (!(actualDocument.getFieldValue(field).equals(updateDocument.getFieldValue(field)))) {
                if (documentAdditions == null) {
                    documentAdditions = new COTSDetails();
                }
                if (documentDeletions == null) {
                    documentDeletions = new COTSDetails();
                }
                documentAdditions.setFieldValue(field, updateDocument.getFieldValue(field));
                documentDeletions.setFieldValue(field, actualDocument.getFieldValue(field));
            }
        }
    }
    request.getReleaseAdditions().setCotsDetails(documentAdditions);
    request.getReleaseDeletions().setCotsDetails(documentDeletions);
    return request;
}
Also used : COTSDetails(org.eclipse.sw360.datahandler.thrift.components.COTSDetails)

Example 55 with Release._Fields

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

the class ComponentModerationRequestGenerator method setAdditionsAndDeletions.

@Override
public ModerationRequest setAdditionsAndDeletions(ModerationRequest request, Component updateComponent, Component actualComponent) {
    updateDocument = updateComponent;
    actualDocument = actualComponent;
    documentAdditions = new Component();
    documentDeletions = new Component();
    // required fields:
    documentAdditions.setName(updateComponent.getName());
    documentAdditions.setId(actualComponent.getId());
    documentDeletions.setName(actualComponent.getName());
    documentDeletions.setId(actualComponent.getId());
    for (Component._Fields field : Component._Fields.values()) {
        if (actualComponent.getFieldValue(field) == null) {
            documentAdditions.setFieldValue(field, updateComponent.getFieldValue(field));
        } else if (updateComponent.getFieldValue(field) == null) {
            documentDeletions.setFieldValue(field, actualComponent.getFieldValue(field));
        } else if (!actualComponent.getFieldValue(field).equals(updateComponent.getFieldValue(field))) {
            switch(field) {
                // ignored fields
                case PERMISSIONS:
                case DOCUMENT_STATE:
                // releases and related fields are not updated via moderation requests
                case RELEASES:
                case RELEASE_IDS:
                case MAIN_LICENSE_IDS:
                case LANGUAGES:
                case OPERATING_SYSTEMS:
                case VENDOR_NAMES:
                    break;
                case ATTACHMENTS:
                    dealWithAttachments(Component._Fields.ATTACHMENTS);
                    break;
                case ROLES:
                    dealWithCustomMap(Component._Fields.ROLES);
                    break;
                default:
                    dealWithBaseTypes(field, Component.metaDataMap.get(field));
            }
        }
    }
    request.setComponentAdditions(documentAdditions);
    request.setComponentDeletions(documentDeletions);
    return request;
}
Also used : Component(org.eclipse.sw360.datahandler.thrift.components.Component)

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