use of com.epam.pipeline.entity.metadata.MetadataEntity 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;
}
use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.
the class EntityLineProcessor method getOrCreateEntity.
private MetadataEntity getOrCreateEntity(String id) {
MetadataEntity entity = currentResults.get(id);
if (entity == null) {
entity = new MetadataEntity();
entity.setExternalId(id);
entity.setParent(parent);
entity.setClassEntity(metadataClass);
entity.setData(new HashMap<>());
currentResults.put(id, entity);
}
return entity;
}
use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.
the class MetadataEntityConverter method convert.
public static Map<String, String> convert(List<MetadataEntity> entities) {
Map<FireCloudClass, FireCloudData> content = new EnumMap<>(FireCloudClass.class);
entities.forEach(entity -> {
FireCloudClass fireCloudClass = entity.getClassEntity().getFireCloudClassName();
Assert.notNull(fireCloudClass, "Fire Cloud class must be specified.");
FireCloudData dataContent = content.computeIfAbsent(fireCloudClass, key -> new FireCloudData(fireCloudClass, entity.getData()));
dataContent.put(entity);
});
Map<String, String> result = new HashMap<>();
content.forEach(((fireCloudClass, fireCloudData) -> {
result.put(fireCloudClass.getFileName(), fireCloudData.getContent());
if (fireCloudData.isSet()) {
result.put(fireCloudClass.getMembershipFileName(), fireCloudData.getMembershipContent());
}
}));
return result;
}
use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.
the class FolderDaoTest method testCreateAndLoadFolderWithMetadata.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testCreateAndLoadFolderWithMetadata() {
Folder folder = getFolder();
// create
folderDao.createFolder(folder);
Map<String, Integer> metadata = new HashMap<>();
metadata.put(CLASS_NAME_1, 1);
folder.setMetadata(metadata);
// add metadata
MetadataEntity metadataEntity = new MetadataEntity();
metadataEntity.setName(TEST_ENTITY_NAME_1);
MetadataClass metadataClass = createMetadataClass();
metadataEntity.setClassEntity(metadataClass);
metadataEntity.setParent(folder);
Map<String, PipeConfValue> data = new HashMap<>();
data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
metadataEntity.setData(data);
metadataEntityDao.createMetadataEntity(metadataEntity);
Folder loaded = folderDao.loadFolder(folder.getId());
assertEquals(folder.getId(), loaded.getId());
assertEquals(folder.getName(), loaded.getName());
assertEquals(folder.getMetadata(), loaded.getMetadata());
assertNull(folder.getParentId());
Map<String, Integer> loadedMetadata = loaded.getMetadata();
assertTrue(!loadedMetadata.isEmpty() && loadedMetadata.size() == 1);
assertEquals(metadataEntity.getClassEntity().getName(), loadedMetadata.keySet().toArray()[0]);
assertEquals(1, loadedMetadata.get(CLASS_NAME_1).intValue());
}
use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.
the class MetadataEntityConverterTest method shouldFailIfPairWithoutParticipantAttribute.
@Test(expected = IllegalArgumentException.class)
public void shouldFailIfPairWithoutParticipantAttribute() {
Map<String, PipeConfValue> pairData = new HashMap<>();
pairData.put(CASE_SAMPLE_ARGUMENT, new PipeConfValue(SAMPLE_ATTRIBUTE_TYPE, SAMPLE_ENTITY_ID2));
pairData.put(CONTROL_SAMPLE_ARGUMENT, new PipeConfValue(SAMPLE_ATTRIBUTE_TYPE, SAMPLE_ENTITY_ID1));
MetadataEntity pair = getEntity(pairClass, PAIR_ENTITY_ID1, pairData);
MetadataEntityConverter.convert(Collections.singletonList(pair));
}
Aggregations