Search in sources :

Example 11 with EntityVO

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());
}
Also used : HashMap(java.util.HashMap) FolderTemplate(com.epam.pipeline.entity.templates.FolderTemplate) Folder(com.epam.pipeline.entity.pipeline.Folder) EntityVO(com.epam.pipeline.controller.vo.EntityVO) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) AclPermissionEntry(com.epam.pipeline.entity.security.acl.AclPermissionEntry) DataStorageWithMetadataVO(com.epam.pipeline.controller.vo.data.storage.DataStorageWithMetadataVO) PermissionVO(com.epam.pipeline.controller.vo.PermissionVO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with EntityVO

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;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Folder(com.epam.pipeline.entity.pipeline.Folder) DataStorageFolder(com.epam.pipeline.entity.datastorage.DataStorageFolder)

Example 13 with EntityVO

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;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage)

Example 14 with EntityVO

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);
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with EntityVO

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);
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EntityVO (com.epam.pipeline.controller.vo.EntityVO)40 Transactional (org.springframework.transaction.annotation.Transactional)22 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)14 Test (org.junit.Test)14 Folder (com.epam.pipeline.entity.pipeline.Folder)13 MetadataEntry (com.epam.pipeline.entity.metadata.MetadataEntry)12 Issue (com.epam.pipeline.entity.issue.Issue)11 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)8 HashMap (java.util.HashMap)5 IssueVO (com.epam.pipeline.controller.vo.IssueVO)4 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)4 Before (org.junit.Before)4 Attachment (com.epam.pipeline.entity.issue.Attachment)3 AclClass (com.epam.pipeline.entity.security.acl.AclClass)3 Date (java.util.Date)3 Map (java.util.Map)3 AfterReturning (org.aspectj.lang.annotation.AfterReturning)3 MetadataVO (com.epam.pipeline.controller.vo.MetadataVO)2 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)2 IssueComment (com.epam.pipeline.entity.issue.IssueComment)2