use of com.epam.pipeline.entity.metadata.PipeConfValue in project cloud-pipeline by epam.
the class FolderManagerTest method shouldCloneFolderWithMetadataEntities.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void shouldCloneFolderWithMetadataEntities() {
Folder sourceFolder = new Folder();
sourceFolder.setName(FOLDER_TO_CLONE);
folderManager.create(sourceFolder);
Map<String, PipeConfValue> metadata = new HashMap<>();
metadata.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
MetadataClass metadataClass = metadataEntityManager.createMetadataClass(TEST_NAME);
MetadataEntityVO metadataEntity = new MetadataEntityVO();
metadataEntity.setParentId(sourceFolder.getId());
metadataEntity.setClassName(metadataClass.getName());
metadataEntity.setClassId(metadataClass.getId());
metadataEntity.setData(metadata);
metadataEntity.setEntityName(TEST_NAME);
MetadataEntity expectedMetadata = metadataEntityManager.updateMetadataEntity(metadataEntity);
Folder childSourceFolder = new Folder();
childSourceFolder.setName(CHILD_FOLDER_TO_CLONE);
childSourceFolder.setParentId(sourceFolder.getId());
folderManager.create(childSourceFolder);
metadataEntity.setParentId(childSourceFolder.getId());
metadataEntityManager.updateMetadataEntity(metadataEntity);
Folder destinationFolder = new Folder();
destinationFolder.setName(TEST_NAME);
folderManager.create(destinationFolder);
folderManager.cloneFolder(sourceFolder.getId(), destinationFolder.getId(), TEST_CLONE_PREFIX);
destinationFolder = folderManager.loadByNameOrId(TEST_NAME);
destinationFolder = folderManager.load(destinationFolder.getId());
Folder clonedFolder = destinationFolder.getChildFolders().get(0);
MetadataEntity clonedMetadata = metadataEntityManager.loadMetadataEntityByClassNameAndFolderId(clonedFolder.getId(), metadataClass.getName()).get(0);
assertMetadataEntity(expectedMetadata, clonedMetadata);
Folder clonedChildFolder = clonedFolder.getChildFolders().get(0);
clonedMetadata = metadataEntityManager.loadMetadataEntityByClassNameAndFolderId(clonedChildFolder.getId(), metadataClass.getName()).get(0);
assertMetadataEntity(expectedMetadata, clonedMetadata);
}
use of com.epam.pipeline.entity.metadata.PipeConfValue in project cloud-pipeline by epam.
the class FolderTemplateManagerTest method createFolderFromTemplateTest.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = TEST_USER)
public void createFolderFromTemplateTest() throws IOException {
Map<String, PipeConfValue> metadata = new HashMap<>();
metadata.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
DataStorageWithMetadataVO dataStorageVO = new DataStorageWithMetadataVO();
dataStorageVO.setName(DATASTORAGE_NAME_1);
dataStorageVO.setType(DataStorageType.S3);
dataStorageVO.setPath(TEST_PATH);
dataStorageVO.setMetadata(metadata);
PermissionVO permissionVO = new PermissionVO();
permissionVO.setMask(AclPermission.READ.getMask());
permissionVO.setUserName(TEST_ROLE);
permissionVO.setPrincipal(false);
FolderTemplate childFolderTemplate1 = FolderTemplate.builder().name(CHILD_TEMPLATE_FOLDER_NAME_1).build();
FolderTemplate folderTemplate = FolderTemplate.builder().name(TEMPLATE_FOLDER_NAME).datastorages(Stream.of(dataStorageVO).collect(Collectors.toList())).children(Stream.of(childFolderTemplate1).collect(Collectors.toList())).metadata(metadata).permissions(Stream.of(permissionVO).collect(Collectors.toList())).build();
Folder folder = new Folder();
folder.setName(TEMPLATE_FOLDER_NAME);
folderTemplateManager.createFolderFromTemplate(folder, folderTemplate);
Folder savedRootFolder = folderManager.loadByNameOrId(TEMPLATE_FOLDER_NAME);
savedRootFolder = folderManager.load(savedRootFolder.getId());
Assert.assertNotNull(savedRootFolder);
Long rootFolderId = savedRootFolder.getId();
List<EntityVO> metadataEntries = Collections.singletonList(new EntityVO(rootFolderId, AclClass.FOLDER));
Assert.assertEquals(metadata, metadataManager.listMetadataItems(metadataEntries).get(0).getData());
AbstractDataStorage clonedDataStorage = savedRootFolder.getStorages().get(0);
clonedDataStorage = dataStorageManager.load(clonedDataStorage.getId());
Assert.assertTrue(clonedDataStorage.getName().startsWith(DATASTORAGE_NAME_1));
Assert.assertTrue(clonedDataStorage.getPath().startsWith(TEST_PATH));
metadataEntries = Collections.singletonList(new EntityVO(clonedDataStorage.getId(), AclClass.DATA_STORAGE));
Assert.assertEquals(metadata, metadataManager.listMetadataItems(metadataEntries).get(0).getData());
List<AclPermissionEntry> rootFolderPermissions = permissionManager.getPermissions(rootFolderId, AclClass.FOLDER).getPermissions();
Assert.assertEquals(1, rootFolderPermissions.size());
AclPermissionEntry actualPermission = rootFolderPermissions.get(0);
Assert.assertEquals(permissionVO.getMask(), actualPermission.getMask());
Assert.assertEquals(permissionVO.getPrincipal(), actualPermission.getSid().isPrincipal());
Assert.assertEquals(permissionVO.getUserName(), actualPermission.getSid().getName());
Folder savedChildFolder = folderManager.loadByNameOrId(TEMPLATE_FOLDER_NAME + "/" + CHILD_TEMPLATE_FOLDER_NAME_1);
Assert.assertNotNull(savedChildFolder);
Assert.assertEquals(rootFolderId, savedChildFolder.getParentId());
}
use of com.epam.pipeline.entity.metadata.PipeConfValue in project cloud-pipeline by epam.
the class MetadataEntityLoaderTest method shouldLoadMetadataEntityTest.
@Test
void shouldLoadMetadataEntityTest() throws EntityNotFoundException {
MetadataClass metadataClass = new MetadataClass(1L, "Sample");
MetadataEntity expectedMetadataEntity = new MetadataEntity();
expectedMetadataEntity.setClassEntity(metadataClass);
expectedMetadataEntity.setId(1L);
expectedMetadataEntity.setExternalId("external");
expectedMetadataEntity.setParent(new Folder(1L));
expectedMetadataEntity.setName(TEST_NAME);
expectedMetadataEntity.setOwner(TEST_NAME);
expectedMetadataEntity.setData(Collections.singletonMap(TEST_KEY, new PipeConfValue("string", TEST_VALUE)));
MetadataEntityLoader metadataEntityLoader = new MetadataEntityLoader(apiClient);
when(apiClient.loadMetadataEntity(anyLong())).thenReturn(expectedMetadataEntity);
Optional<EntityContainer<MetadataEntity>> container = metadataEntityLoader.loadEntity(1L);
EntityContainer<MetadataEntity> metadataEntityContainer = container.orElseThrow(AssertionError::new);
MetadataEntity actualMetadataEntity = metadataEntityContainer.getEntity();
assertNotNull(actualMetadataEntity);
verifyMetadataEntity(expectedMetadataEntity, actualMetadataEntity);
verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, metadataEntityContainer.getPermissions());
verifyMetadata(EXPECTED_METADATA, new ArrayList<>(metadataEntityContainer.getMetadata().values()));
}
use of com.epam.pipeline.entity.metadata.PipeConfValue in project cloud-pipeline by epam.
the class MetadataManager method updateMetadataItemKey.
@Transactional(propagation = Propagation.REQUIRED)
public MetadataEntry updateMetadataItemKey(MetadataVO metadataVO) {
validateMetadata(metadataVO);
EntityVO entity = metadataVO.getEntity();
checkEntityExistence(entity.getEntityId(), entity.getEntityClass());
MetadataEntry metadataToSave = metadataEntryMapper.toMetadataEntry(metadataVO);
MetadataEntry existingMetadata = listMetadataItem(metadataToSave.getEntity(), false);
if (existingMetadata == null) {
LOGGER.debug("Could not find such metadata. A new one will be created.");
metadataDao.registerMetadataItem(metadataToSave);
} else {
Map.Entry<String, PipeConfValue> metadataEntry = metadataToSave.getData().entrySet().iterator().next();
metadataDao.uploadMetadataItemKey(metadataToSave.getEntity(), metadataEntry.getKey(), metadataEntry.getValue().getValue(), metadataEntry.getValue().getType());
}
return metadataDao.loadMetadataItem(entity);
}
use of com.epam.pipeline.entity.metadata.PipeConfValue 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