Search in sources :

Example 26 with MetadataEntity

use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.

the class MetadataDownloadManagerTest method getInputStreamShouldThrowIfRequestedFileFormatIsNotSupported.

@Test(expected = IllegalArgumentException.class)
public void getInputStreamShouldThrowIfRequestedFileFormatIsNotSupported() {
    final List<MetadataEntity> entities = Collections.singletonList(new MetadataEntity());
    when(metadataEntityManager.loadMetadataEntityByClassNameAndFolderId(FOLDER_ID, SAMPLE)).thenReturn(entities);
    manager.getInputStream(FOLDER_ID, SAMPLE, "unsupportedFileFormat");
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) Test(org.junit.Test)

Example 27 with MetadataEntity

use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.

the class FolderManagerGetProjectTest method getProjectShouldWorkWithMetadataAsInputEntity.

@Test
public void getProjectShouldWorkWithMetadataAsInputEntity() {
    MetadataEntity metadataEntity = new MetadataEntity();
    metadataEntity.setId(1L);
    metadataEntity.setParent(folder3);
    Mockito.when(entityManager.load(Matchers.any(AclClass.class), Matchers.any(Long.class))).thenReturn(metadataEntity);
    Folder actualFolder = folderManager.getProject(metadataEntity.getId(), AclClass.METADATA_ENTITY);
    assertFolders(folder2, actualFolder);
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) Folder(com.epam.pipeline.entity.pipeline.Folder) AclClass(com.epam.pipeline.entity.security.acl.AclClass) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Example 28 with MetadataEntity

use of com.epam.pipeline.entity.metadata.MetadataEntity 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 29 with MetadataEntity

use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.

the class MetadataEntityMapper method map.

@Override
public XContentBuilder map(final EntityContainer<MetadataEntity> container) {
    MetadataEntity entity = container.getEntity();
    try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
        jsonBuilder.startObject();
        jsonBuilder.field(DOC_TYPE_FIELD, SearchDocumentType.METADATA_ENTITY.name()).field("id", entity.getId()).field("externalId", entity.getExternalId()).field("parentId", Optional.ofNullable(entity.getParent()).map(BaseEntity::getId).orElse(null)).field("name", StringUtils.defaultString(entity.getName(), entity.getExternalId()));
        buildEntityClass(entity.getClassEntity(), jsonBuilder);
        buildPermissions(container.getPermissions(), jsonBuilder);
        buildMap(prepareEntityMetadata(entity.getData()), jsonBuilder, "fields");
        jsonBuilder.endObject();
        return jsonBuilder;
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to create elasticsearch document for metadata: ", e);
    }
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 30 with MetadataEntity

use of com.epam.pipeline.entity.metadata.MetadataEntity 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)

Aggregations

MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)48 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)22 Test (org.junit.Test)22 Transactional (org.springframework.transaction.annotation.Transactional)14 MetadataClass (com.epam.pipeline.entity.metadata.MetadataClass)12 Folder (com.epam.pipeline.entity.pipeline.Folder)10 HashMap (java.util.HashMap)9 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)7 List (java.util.List)7 Map (java.util.Map)6 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)5 IOException (java.io.IOException)5 MetadataReadingException (com.epam.pipeline.exception.MetadataReadingException)4 FolderManager (com.epam.pipeline.manager.pipeline.FolderManager)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Propagation (org.springframework.transaction.annotation.Propagation)4 AclClass (com.epam.pipeline.entity.security.acl.AclClass)3 com.epam.pipeline.manager.metadata.parser (com.epam.pipeline.manager.metadata.parser)3