use of com.epam.pipeline.exception.MetadataReadingException in project cloud-pipeline by epam.
the class MetadataEntityHeaderParser method readHeader.
public MetadataHeader readHeader(InputStream stream) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
String line = reader.readLine();
if (StringUtils.isBlank(line)) {
throw new MetadataReadingException("Input file doesn't have expected header.");
}
String[] columns = line.split(delimiter);
if (columns.length < 1) {
throw new MetadataReadingException("At least one column should be present.");
}
MetadataHeader header = new MetadataHeader(headerParser.readClassColumn(columns[0]));
for (int i = 1; i < columns.length; i++) {
header.addField(i, headerParser.readFieldColumn(columns[i]));
}
return header;
} catch (IOException e) {
throw new MetadataReadingException(e.getMessage(), e);
}
}
use of com.epam.pipeline.exception.MetadataReadingException in project cloud-pipeline by epam.
the class MetadataUploadManager method readFile.
private MetadataParsingResult readFile(Long parentId, MultipartFile file) {
try {
final Folder parent = folderManager.load(parentId);
String delimiter = MetadataParsingUtils.getDelimiterFromFileExtension(file.getOriginalFilename());
byte[] inputData = file.getBytes();
MetadataHeader header = new MetadataEntityHeaderParser(delimiter).readHeader(ByteSource.wrap(inputData).openStream());
validateTypes(header, parentId);
MetadataClass metadataClass = getOrCreateClass(header.getClassName());
return new MetadataEntityReader(delimiter, parent, metadataClass).readData(ByteSource.wrap(inputData).openStream(), header.getFields());
} catch (IOException e) {
throw new MetadataReadingException(e.getMessage(), e);
}
}
use of com.epam.pipeline.exception.MetadataReadingException in project cloud-pipeline by epam.
the class EntityLineProcessor method processLine.
@Override
public boolean processLine(String line) throws IOException {
if (StringUtils.isBlank(line)) {
return false;
}
if (!headerProcessed) {
headerProcessed = true;
return true;
}
String[] chunks = StringUtils.splitPreserveAllTokens(line, delimiter);
if (chunks.length != fields.size() + 1) {
throw new MetadataReadingException("Size of line doesn't match header");
}
MetadataEntity entity = getOrCreateEntity(chunks[0]);
fields.forEach((index, field) -> {
String value = chunks[index];
if (StringUtils.isNotBlank(value)) {
if (field.isReference()) {
referenceTypes.putIfAbsent(field.getType(), new HashSet<>());
referenceTypes.get(field.getType()).add(value);
}
if (field.isMultiValue()) {
arrayValues.putIfAbsent(entity.getExternalId(), new HashMap<>());
}
PipeConfValue previousValue = entity.getData().get(field.getName());
Map<String, Set<String>> currentArrayValue = arrayValues.get(entity.getExternalId());
entity.getData().put(field.getName(), getValue(field, value, previousValue, currentArrayValue));
}
});
return true;
}
Aggregations