Search in sources :

Example 1 with MetadataReadingException

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) MetadataReadingException(com.epam.pipeline.exception.MetadataReadingException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 2 with MetadataReadingException

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);
    }
}
Also used : MetadataEntityReader(com.epam.pipeline.manager.metadata.parser.MetadataEntityReader) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) MetadataReadingException(com.epam.pipeline.exception.MetadataReadingException) MetadataHeader(com.epam.pipeline.manager.metadata.parser.MetadataHeader) IOException(java.io.IOException) Folder(com.epam.pipeline.entity.pipeline.Folder) MetadataEntityHeaderParser(com.epam.pipeline.manager.metadata.parser.MetadataEntityHeaderParser)

Example 3 with MetadataReadingException

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;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) Set(java.util.Set) HashSet(java.util.HashSet) MetadataReadingException(com.epam.pipeline.exception.MetadataReadingException) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue)

Aggregations

MetadataReadingException (com.epam.pipeline.exception.MetadataReadingException)3 IOException (java.io.IOException)2 MetadataClass (com.epam.pipeline.entity.metadata.MetadataClass)1 MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)1 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)1 Folder (com.epam.pipeline.entity.pipeline.Folder)1 MetadataEntityHeaderParser (com.epam.pipeline.manager.metadata.parser.MetadataEntityHeaderParser)1 MetadataEntityReader (com.epam.pipeline.manager.metadata.parser.MetadataEntityReader)1 MetadataHeader (com.epam.pipeline.manager.metadata.parser.MetadataHeader)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1