use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.
the class ConvertRecord method fillLicenses.
public static List<License> fillLicenses(List<CSVRecord> records, Map<Integer, LicenseType> licenseTypeMap, Map<Integer, Todo> todoMap, Map<Integer, Risk> riskMap, Map<String, Set<Integer>> licenseTodo, Map<String, Set<Integer>> licenseRisk) {
List<License> licenses = new ArrayList<>(records.size());
for (CSVRecord record : records) {
if (record.size() < 7)
break;
String identifier = record.get(0);
String fullname = record.get(1);
License license = new License().setId(identifier).setFullname(fullname);
String typeString = record.get(2);
if (!Strings.isNullOrEmpty(typeString) && !"NULL".equals(typeString)) {
Integer typeId = Integer.parseInt(typeString);
LicenseType licenseType = licenseTypeMap.get(typeId);
license.setLicenseType(licenseType);
}
String gplv2CompatString = record.get(3);
if (!Strings.isNullOrEmpty(gplv2CompatString) && !"NULL".equals(gplv2CompatString)) {
Ternary gplv2Compat = ThriftEnumUtils.stringToEnum(gplv2CompatString, Ternary.class);
license.setGPLv2Compat(gplv2Compat);
}
String gplv3CompatString = record.get(4);
if (!Strings.isNullOrEmpty(gplv3CompatString) && !"NULL".equals(gplv3CompatString)) {
Ternary gplv3Compat = ThriftEnumUtils.stringToEnum(gplv3CompatString, Ternary.class);
license.setGPLv3Compat(gplv3Compat);
}
String reviewdate = record.get(5);
license.setReviewdate(ConvertUtil.parseDate(reviewdate));
String text = record.get(6);
license.setText(text);
if (record.size() > 7) {
String externalLink = record.get(7);
license.setExternalLicenseLink(externalLink);
}
if (record.size() > 8) {
Optional.ofNullable(record.get(8)).map(json -> gson.fromJson(json, new TypeToken<Map<String, String>>() {
}.getType())).map(o -> (Map<String, String>) o).ifPresent(license::setExternalIds);
}
// Add all risks
Set<Integer> riskIds = licenseRisk.get(identifier);
if (riskIds != null) {
for (int riskId : riskIds) {
Risk risk = riskMap.get(riskId);
if (risk != null) {
license.addToRiskDatabaseIds(risk.getId());
}
}
}
// Add all todos
Set<Integer> todoIds = licenseTodo.get(identifier);
if (todoIds != null) {
for (int todoId : todoIds) {
Todo todo = todoMap.get(todoId);
if (todo != null) {
license.addToTodoDatabaseIds(todo.getId());
}
}
}
licenses.add(license);
}
return licenses;
}
use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.
the class ConvertRecordTest method prepare.
@Before
public void prepare() {
emptyRecord = readToRecord(" ");
String tooSmall = "header\n 1, prop";
tooSmallRecord = readToRecord(tooSmall);
String emptyProp = "header\n 1,,val";
emptyPropRecord = readToRecord(emptyProp);
String whiteProp = "header\n 1, ,val";
whitePropRecord = readToRecord(whiteProp);
String emptyValue = "header\n 1,prop,";
emptyValRecord = readToRecord(emptyValue);
String whiteValue = "header\n 1,prop, ";
whiteValRecord = readToRecord(whiteValue);
String smallestPossible = "headers\n 1,prop1,val1";
smallestPossibleRecord = readToRecord(smallestPossible);
String full = "headers\n 1,A,A1 \n 2,A,A2 \n 3,A,A3 \n 4,B,B1 \n 5,B,B2";
fullRecord = readToRecord(full);
String fullTodo = "header \n '1','text1','true','true' \n '2','text2','false','false', '{\"key\": \"value\"}'";
fullTodoRecord = readToRecord(fullTodo);
Map<String, String> todoCustomProperties1 = new HashMap<>();
todoCustomProperties1.put("A", "A1");
Todo todo1 = new Todo().setTodoId(1).setCustomPropertyToValue(todoCustomProperties1);
Map<String, String> todoCustomProperties2 = new HashMap<>();
todoCustomProperties2.put("A", "A2");
todoCustomProperties2.put("C", "C2");
Todo todo2 = new Todo().setTodoId(2).setCustomPropertyToValue(todoCustomProperties2);
todos = Arrays.asList(todo1, todo2);
}
use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.
the class AttachmentContentWrapperTest method testUpdateNonMetadataTouchesAllFields.
public void testUpdateNonMetadataTouchesAllFields() throws Exception {
AttachmentContent source;
source = new AttachmentContent();
source.setFilename("a");
source.setType("b");
source.setContentType("v");
source.setPartsCount("1");
// TODO this is not required !
source.setRemoteUrl("uskt");
AttachmentContentWrapper attachmentContentWrapper = new AttachmentContentWrapper();
attachmentContentWrapper.updateNonMetadata(source);
assertTFields(source, attachmentContentWrapper, AttachmentContentWrapper.class, AttachmentContent._Fields.class);
}
use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.
the class TypeMappings method updateTodoMapWithCustomPropertiesAndWriteToDatabase.
@NotNull
public static Map<Integer, Todo> updateTodoMapWithCustomPropertiesAndWriteToDatabase(LicenseService.Iface licenseClient, Map<Integer, Todo> todoMap, Map<Integer, PropertyWithValue> customPropertiesMap, Map<Integer, Set<Integer>> todoPropertiesMap, User user) throws TException {
for (Integer todoId : todoPropertiesMap.keySet()) {
Todo todo = todoMap.get(todoId);
if (!todo.isSetCustomPropertyToValue()) {
todo.setCustomPropertyToValue(new HashMap<>());
}
for (Integer propertyWithValueId : todoPropertiesMap.get(todoId)) {
PropertyWithValue propertyWithValue = customPropertiesMap.get(propertyWithValueId);
todo.getCustomPropertyToValue().put(propertyWithValue.getProperty(), propertyWithValue.getValue());
}
}
if (todoMap.values().size() > 0) {
final List<Todo> addedTodos = licenseClient.addTodos(todoMap.values().stream().collect(Collectors.toList()), user);
if (addedTodos != null) {
final ImmutableMap<Integer, Todo> addedTodoMap = Maps.uniqueIndex(addedTodos, getTodoIdentifier());
todoMap.putAll(addedTodoMap);
}
}
return todoMap;
}
use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.
the class AttachmentStreamConnector method getAttachmentBundleStream.
/**
* It is highly recommended to close this stream after using to avoid connection leak
*/
public <T> InputStream getAttachmentBundleStream(Set<AttachmentContent> attachments, User user, T context) throws IOException, SW360Exception {
assertNotNull(context);
PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream(in);
new Thread(() -> {
byte[] buffer = new byte[1024];
int length;
try (ZipOutputStream zip = new ZipOutputStream(out)) {
for (AttachmentContent attachment : attachments) {
// TODO: handle attachments with equal name
ZipEntry zipEntry = new ZipEntry(attachment.getFilename());
zip.putNextEntry(zipEntry);
try (InputStream attachmentStream = getAttachmentStream(attachment, user, context)) {
while ((length = attachmentStream.read(buffer)) >= 0) {
zip.write(buffer, 0, length);
}
} catch (TException e) {
log.error("failed to get AttachmentStream, maybe due to permission problems", e);
}
zip.closeEntry();
}
} catch (IOException e) {
log.error("failed to write zip stream", e);
}
}).start();
return in;
}
Aggregations