use of org.eclipse.sw360.datahandler.thrift.components.Component 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;
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ModerationDatabaseHandler method createRequest.
public RequestStatus createRequest(Component component, User user, Boolean isDeleteRequest) {
Component dbcomponent;
try {
dbcomponent = componentDatabaseHandler.getComponent(component.getId(), user);
} catch (SW360Exception e) {
log.error("Could not get original component from database. Could not generate moderation request.", e);
return RequestStatus.FAILURE;
}
// Define moderators
Set<String> moderators = new HashSet<>();
CommonUtils.add(moderators, dbcomponent.getCreatedBy());
try {
String department = getDepartmentByUserEmail(component.getCreatedBy());
CommonUtils.addAll(moderators, getUsersAtLeast(UserGroup.CLEARING_ADMIN, department));
} catch (TException e) {
log.error("Could not get user from database. Clearing admins not added as moderators, since department is missing.");
}
CommonUtils.addAll(moderators, getUsersAtLeast(UserGroup.ADMIN));
ModerationRequest request = createStubRequest(user, isDeleteRequest, component.getId(), moderators);
// Set meta-data
request.setDocumentType(DocumentType.COMPONENT);
request.setDocumentName(SW360Utils.printName(dbcomponent));
// Fill the request
ModerationRequestGenerator generator = new ComponentModerationRequestGenerator();
request = generator.setAdditionsAndDeletions(request, component, dbcomponent);
if (component.isSetComponentType()) {
request.setComponentType(component.getComponentType());
}
addOrUpdate(request, user);
return RequestStatus.SENT_TO_MODERATOR;
}
use of org.eclipse.sw360.datahandler.thrift.components.Component 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.Component in project sw360portal by sw360.
the class CombinedCLIParser method getLicenseInfoParsingResultForExternalId.
@NotNull
private LicenseInfoParsingResult getLicenseInfoParsingResultForExternalId(AttachmentContent attachmentContent, Map<String, Release> releasesByExternalId, Map<String, Set<String>> copyrightSetsByExternalId, Map<String, Set<LicenseNameWithText>> licenseNamesWithTextsByExternalId, String extId) {
LicenseInfo licenseInfo = new LicenseInfo().setFilenames(Arrays.asList(attachmentContent.getFilename()));
licenseInfo.setCopyrights(copyrightSetsByExternalId.get(extId));
licenseInfo.setLicenseNamesWithTexts(licenseNamesWithTextsByExternalId.get(extId));
LicenseInfoParsingResult parsingResult = new LicenseInfoParsingResult().setLicenseInfo(licenseInfo);
Release release = releasesByExternalId.get(extId);
if (release != null) {
parsingResult.setVendor(release.isSetVendor() ? release.getVendor().getShortname() : "");
parsingResult.setName(release.getName());
parsingResult.setVersion(release.getVersion());
} else {
parsingResult.setName("No info found for external component ID " + extId);
}
parsingResult.setStatus(LicenseInfoRequestStatus.SUCCESS);
return parsingResult;
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class TestComponentClient method main.
public static void main(String[] args) throws TException, IOException {
THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080/components/thrift");
TProtocol protocol = new TCompactProtocol(thriftClient);
ComponentService.Iface client = new ComponentService.Client(protocol);
// List<Component> components = client.getComponentSummary(user);
// List<Component> recentComponents = client.getRecentComponents();
// List<Release> releases = client.getReleaseSummary(user);
//
// System.out.println("Fetched " + components.size() + " components from license service");
// System.out.println("Fetched " + releases.size() + " releases from license service");
// System.out.println("Fetched " + recentComponents.size() + " recent components from license service");
//
// String referenceId =null;
// for (Component component : recentComponents) {
// if(referenceId==null) referenceId=component.getId();
// System.out.println(component.getId() + ": " + component.getName());
// }
//
// if(referenceId!=null) {
// System.out.println(client.getComponentById(referenceId, user).toString());
// Component component = new ComponentHandler("http://localhost:5984", "sw360db", "sw360attachments").getComponentById(referenceId, user);
// System.out.println(component.toString());
// System.out.println(client.getComponentById(referenceId, user).toString());
// }
//
// for(Release release : releases) {
// System.out.println(release.toString());
// }
// // This fails with a thrift error... debug!
// if(releases.size()>0) {
// String releaseNameStart = releases.get(0).getName().substring(0,1);
// System.out.println("The following releases start with " + releaseNameStart );
//
// List<Release> releases1 = client.searchReleaseByName(releaseNameStart);
// for(Release release : releases1) {
// System.out.println(release.toString());
// }
//
// }
// final Component cpe = client.getComponentForReportFromCPEId("cpe");
// System.out.println(cpe.toString());
}
Aggregations