use of com.epam.pipeline.controller.vo.EntityVO 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.controller.vo.EntityVO in project cloud-pipeline by epam.
the class DataStorageManager method loadByNameOrId.
public AbstractDataStorage loadByNameOrId(final String identifier) {
AbstractDataStorage dataStorage = null;
if (NumberUtils.isDigits(identifier)) {
dataStorage = dataStorageDao.loadDataStorage(Long.parseLong(identifier));
}
if (dataStorage == null) {
String pathWithName = identifier;
if (pathWithName.startsWith("/")) {
pathWithName = pathWithName.substring(1);
}
if (pathWithName.endsWith("/")) {
pathWithName = pathWithName.substring(0, pathWithName.length() - 1);
}
String[] pathParts = pathWithName.split("/");
String dataStorageName = pathParts[pathParts.length - 1];
Long parentFolderId = null;
if (pathParts.length > 1) {
Folder parentFolder = folderManager.loadByNameOrId(String.join("/", Arrays.asList(pathParts).subList(0, pathParts.length - 1)));
if (parentFolder != null) {
parentFolderId = parentFolder.getId();
}
}
if (parentFolderId != null) {
dataStorage = dataStorageDao.loadDataStorageByNameAndParentId(dataStorageName, parentFolderId);
} else {
dataStorage = dataStorageDao.loadDataStorageByNameOrPath(dataStorageName, dataStorageName);
}
}
Assert.notNull(dataStorage, messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NOT_FOUND, identifier));
dataStorage.setHasMetadata(metadataManager.hasMetadata(new EntityVO(dataStorage.getId(), AclClass.DATA_STORAGE)));
return dataStorage;
}
use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.
the class DataStorageManager method load.
@Override
public AbstractDataStorage load(final Long id) {
AbstractDataStorage dbDataStorage = dataStorageDao.loadDataStorage(id);
Assert.notNull(dbDataStorage, messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NOT_FOUND, id));
dbDataStorage.setHasMetadata(this.metadataManager.hasMetadata(new EntityVO(id, AclClass.DATA_STORAGE)));
return dbDataStorage;
}
use of com.epam.pipeline.controller.vo.EntityVO 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.controller.vo.EntityVO in project cloud-pipeline by epam.
the class MetadataManager method deleteMetadataItemKeys.
@Transactional(propagation = Propagation.REQUIRED)
public MetadataEntry deleteMetadataItemKeys(MetadataVO metadataWithKeysToDelete) {
validateMetadata(metadataWithKeysToDelete);
EntityVO entity = metadataWithKeysToDelete.getEntity();
checkEntityExistence(entity.getEntityId(), entity.getEntityClass());
MetadataEntry metadataEntry = listMetadataItem(entity, true);
Set<String> existingKeys = metadataEntry.getData().keySet();
Set<String> keysToDelete = metadataWithKeysToDelete.getData().keySet();
if (!existingKeys.containsAll(keysToDelete)) {
throw new IllegalArgumentException("Could not delete non existing key.");
}
return metadataDao.deleteMetadataItemKeys(metadataEntry, keysToDelete);
}
Aggregations