Search in sources :

Example 16 with PipeConfValue

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);
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) HashMap(java.util.HashMap) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Folder(com.epam.pipeline.entity.pipeline.Folder) MetadataEntityVO(com.epam.pipeline.controller.vo.metadata.MetadataEntityVO) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with PipeConfValue

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());
}
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 18 with PipeConfValue

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()));
}
Also used : LoaderVerificationUtils.verifyMetadataEntity(com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyMetadataEntity) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) Folder(com.epam.pipeline.entity.pipeline.Folder) Test(org.junit.jupiter.api.Test)

Example 19 with PipeConfValue

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);
}
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 20 with PipeConfValue

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;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) Set(java.util.Set) HashSet(java.util.HashSet) MetadataReadingException(com.epam.pipeline.exception.MetadataReadingException) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue)

Aggregations

PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)41 Test (org.junit.Test)24 MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)21 HashMap (java.util.HashMap)11 Transactional (org.springframework.transaction.annotation.Transactional)11 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)9 EntityVO (com.epam.pipeline.controller.vo.EntityVO)9 Folder (com.epam.pipeline.entity.pipeline.Folder)9 MetadataEntry (com.epam.pipeline.entity.metadata.MetadataEntry)8 FolderWithMetadata (com.epam.pipeline.entity.metadata.FolderWithMetadata)5 MetadataClass (com.epam.pipeline.entity.metadata.MetadataClass)5 PasswordGenerator.generateRandomString (com.epam.pipeline.utils.PasswordGenerator.generateRandomString)5 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)3 MessageConstants (com.epam.pipeline.common.MessageConstants)2 MessageHelper (com.epam.pipeline.common.MessageHelper)2 MetadataVO (com.epam.pipeline.controller.vo.MetadataVO)2 BaseEntity (com.epam.pipeline.entity.BaseEntity)2