use of com.epam.pipeline.entity.metadata.PipeConfValue in project cloud-pipeline by epam.
the class MetadataLineProcessor method processLine.
@Override
public boolean processLine(String line) {
if (StringUtils.isEmpty(line)) {
return false;
}
if (!headerProcessed) {
headerProcessed = true;
String[] splitted = StringUtils.split(line, delimiter);
for (int i = 0; i < splitted.length; i++) {
MetadataColumnTypes type = getColumnType(splitted[i].toUpperCase());
indexes.put(type.name(), i);
}
} else {
String[] splitted = StringUtils.splitPreserveAllTokens(line, delimiter);
if (splitted.length > 3 || splitted.length < 2) {
throw new IllegalArgumentException("Cannot parse line: incorrect length.");
}
String key = splitted[indexes.get(MetadataColumnTypes.KEY.name())];
String value = splitted[indexes.get(MetadataColumnTypes.VALUE.name())];
String type = splitted.length == 2 ? "string" : splitted[indexes.get(MetadataColumnTypes.TYPE.name())];
result.put(key, new PipeConfValue(type, value));
}
return true;
}
use of com.epam.pipeline.entity.metadata.PipeConfValue in project cloud-pipeline by epam.
the class FolderManager method loadAllProjects.
public Folder loadAllProjects() {
Folder root = new Folder();
Set<Pair<String, String>> indicator = parseProjectIndicator();
Map<String, PipeConfValue> projectAttributes = indicator.stream().collect(Collectors.toMap(Pair::getLeft, pair -> new PipeConfValue(null, pair.getRight())));
if (MapUtils.isEmpty(projectAttributes)) {
return root;
}
List<Folder> projects = folderDao.loadAllProjects(projectAttributes).stream().filter(folder -> {
if (folder instanceof FolderWithMetadata) {
FolderWithMetadata folderWithMetadata = (FolderWithMetadata) folder;
Map<String, PipeConfValue> attributes = folderWithMetadata.getData();
return containsProjectIndicator(indicator, attributes);
}
return false;
}).collect(Collectors.toList());
root.setChildFolders(projects);
return root;
}
use of com.epam.pipeline.entity.metadata.PipeConfValue in project cloud-pipeline by epam.
the class FolderManager method getProjectFolder.
FolderWithMetadata getProjectFolder(Map<Long, FolderWithMetadata> folders, Long id, Set<Pair<String, String>> projectIndicators) {
FolderWithMetadata folder = folders.get(id);
if (folder == null) {
return null;
}
Map<String, PipeConfValue> metadata = folder.getData();
if (MapUtils.isEmpty(metadata)) {
LOGGER.debug("Can not detect project folder: metadata not found.");
return continueSearch(folders, projectIndicators, folder);
}
if (containsProjectIndicator(projectIndicators, metadata)) {
return folder;
}
return continueSearch(folders, projectIndicators, folder);
}
use of com.epam.pipeline.entity.metadata.PipeConfValue in project cloud-pipeline by epam.
the class MetadataDaoTest method testShouldSearchMetadataByClassAndKeyValuePair.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testShouldSearchMetadataByClassAndKeyValuePair() {
EntityVO entityVO = new EntityVO(ID_1, CLASS_1);
Map<String, PipeConfValue> data = new HashMap<>();
data.put(DATA_KEY_1, new PipeConfValue(null, DATA_VALUE_1));
data.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_1));
MetadataEntry metadataToSave = new MetadataEntry();
metadataToSave.setEntity(entityVO);
metadataToSave.setData(data);
metadataDao.registerMetadataItem(metadataToSave);
EntityVO entityVO2 = new EntityVO(ID_1, CLASS_2);
metadataToSave.setEntity(entityVO2);
metadataToSave.setData(data);
metadataDao.registerMetadataItem(metadataToSave);
List<EntityVO> loadedEntities = metadataDao.searchMetadataByClassAndKeyValue(CLASS_1, Collections.singletonMap(DATA_KEY_1, new PipeConfValue(null, DATA_VALUE_1)));
Assert.assertEquals(1, loadedEntities.size());
Assert.assertEquals(entityVO, loadedEntities.get(0));
}
use of com.epam.pipeline.entity.metadata.PipeConfValue in project cloud-pipeline by epam.
the class MetadataDaoTest method testOneMetadata.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testOneMetadata() {
EntityVO entityVO = new EntityVO(ID_1, CLASS_1);
Map<String, PipeConfValue> data = new HashMap<>();
data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
MetadataEntry metadataToSave = new MetadataEntry();
metadataToSave.setEntity(entityVO);
metadataToSave.setData(data);
// metadata registration
metadataDao.registerMetadataItem(metadataToSave);
MetadataEntry createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
Assert.assertEquals(data, createdMetadata.getData());
// add key to metadata
data.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_2));
metadataDao.uploadMetadataItemKey(entityVO, DATA_KEY_2, DATA_VALUE_2, DATA_TYPE_2);
createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
Assert.assertEquals(data, createdMetadata.getData());
// delete key from metadata
data.clear();
data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
metadataDao.deleteMetadataItemKey(entityVO, DATA_KEY_2);
createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
Assert.assertEquals(data, createdMetadata.getData());
// update metadata
data.clear();
data.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_2));
metadataToSave.setData(data);
metadataDao.uploadMetadataItem(metadataToSave);
createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
Assert.assertEquals(data, createdMetadata.getData());
// delete several keys from metadata
data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
data.put(DATA_KEY_3, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_1));
metadataToSave.setData(data);
Set<String> keysToDelete = new HashSet<>();
keysToDelete.add(DATA_KEY_1);
keysToDelete.add(DATA_KEY_3);
keysToDelete.add(NON_EXISTING_DATA_KEY);
metadataDao.deleteMetadataItemKeys(metadataToSave, keysToDelete);
createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
data.remove(DATA_KEY_1);
data.remove(DATA_KEY_3);
Assert.assertEquals(data, createdMetadata.getData());
// delete metadata
metadataDao.deleteMetadataItem(entityVO);
createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertNull(createdMetadata);
}
Aggregations