use of org.apache.commons.lang3.StringUtils.isNotEmpty in project thingsboard by thingsboard.
the class AbstractBulkImportService method saveKvs.
private void saveKvs(SecurityUser user, E entity, Map<ColumnMapping, ParsedValue> data) {
Arrays.stream(BulkImportColumnType.values()).filter(BulkImportColumnType::isKv).map(kvType -> {
JsonObject kvs = new JsonObject();
data.entrySet().stream().filter(dataEntry -> dataEntry.getKey().getType() == kvType && StringUtils.isNotEmpty(dataEntry.getKey().getKey())).forEach(dataEntry -> kvs.add(dataEntry.getKey().getKey(), dataEntry.getValue().toJsonPrimitive()));
return Map.entry(kvType, kvs);
}).filter(kvsEntry -> kvsEntry.getValue().entrySet().size() > 0).forEach(kvsEntry -> {
BulkImportColumnType kvType = kvsEntry.getKey();
if (kvType == BulkImportColumnType.SHARED_ATTRIBUTE || kvType == BulkImportColumnType.SERVER_ATTRIBUTE) {
saveAttributes(user, entity, kvsEntry, kvType);
} else {
saveTelemetry(user, entity, kvsEntry);
}
});
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project thingsboard by thingsboard.
the class AbstractBulkImportService method parseData.
private List<EntityData> parseData(BulkImportRequest request) throws Exception {
List<List<String>> records = CsvUtils.parseCsv(request.getFile(), request.getMapping().getDelimiter());
AtomicInteger linesCounter = new AtomicInteger(0);
if (request.getMapping().getHeader()) {
records.remove(0);
linesCounter.incrementAndGet();
}
List<ColumnMapping> columnsMappings = request.getMapping().getColumns();
return records.stream().map(record -> {
EntityData entityData = new EntityData();
Stream.iterate(0, i -> i < record.size(), i -> i + 1).map(i -> Map.entry(columnsMappings.get(i), record.get(i))).filter(entry -> StringUtils.isNotEmpty(entry.getValue())).forEach(entry -> {
if (!entry.getKey().getType().isKv()) {
entityData.getFields().put(entry.getKey().getType(), entry.getValue());
} else {
Map.Entry<DataType, Object> castResult = TypeCastUtil.castValue(entry.getValue());
entityData.getKvs().put(entry.getKey(), new ParsedValue(castResult.getValue(), castResult.getKey()));
}
});
entityData.setLineNumber(linesCounter.incrementAndGet());
return entityData;
}).collect(Collectors.toList());
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project incubator-servicecomb-java-chassis by apache.
the class PojoOperationGenerator method wrapParametersToBody.
private void wrapParametersToBody(List<ParameterGenerator> bodyFields) {
String simpleRef = MethodUtils.findSwaggerMethodName(method) + "Body";
bodyModel = new ModelImpl();
bodyModel.setType(ModelImpl.OBJECT);
for (ParameterGenerator parameterGenerator : bodyFields) {
// to collect all information by swagger mechanism
// must have a parameter type
// but all these parameters will be wrap to be one body parameter, their parameter type must be null
// so we first set to be BODY, after collected, set back to be null
parameterGenerator.setHttpParameterType(HttpParameterType.BODY);
scanMethodParameter(parameterGenerator);
Property property = ModelConverters.getInstance().readAsProperty(parameterGenerator.getGenericType());
property.setDescription(parameterGenerator.getGeneratedParameter().getDescription());
bodyModel.addProperty(parameterGenerator.getParameterName(), property);
parameterGenerator.setHttpParameterType(null);
}
swagger.addDefinition(simpleRef, bodyModel);
SwaggerGeneratorFeature feature = swaggerGenerator.getSwaggerGeneratorFeature();
// if not care for this, then can just delete all logic about EXT_JAVA_CLASS/EXT_JAVA_INTF
if (feature.isExtJavaClassInVendor() && bodyFields.size() > 1 && StringUtils.isNotEmpty(feature.getPackageName())) {
bodyModel.getVendorExtensions().put(SwaggerConst.EXT_JAVA_CLASS, feature.getPackageName() + "." + simpleRef);
}
RefModel refModel = new RefModel();
refModel.setReference("#/definitions/" + simpleRef);
bodyParameter = new BodyParameter();
bodyParameter.name(simpleRef);
bodyParameter.setSchema(refModel);
bodyParameter.setName(parameterGenerators.size() == 1 ? parameterGenerators.get(0).getParameterName() : simpleRef);
List<ParameterGenerator> newParameterGenerators = new ArrayList<>();
newParameterGenerators.add(new ParameterGenerator(bodyParameter.getName(), Collections.emptyList(), null, HttpParameterType.BODY, bodyParameter));
parameterGenerators.stream().filter(p -> p.getHttpParameterType() != null).forEach(p -> newParameterGenerators.add(p));
parameterGenerators = newParameterGenerators;
}
Aggregations