Search in sources :

Example 16 with MetadataClass

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

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

the class MetadataEntityVO method convertToMetadataEntity.

public MetadataEntity convertToMetadataEntity() {
    MetadataEntity metadataEntity = new MetadataEntity();
    MetadataClass metadataClass = new MetadataClass();
    metadataClass.setId(classId);
    metadataClass.setName(className);
    if (parentId != null) {
        metadataEntity.setParent(new Folder(parentId));
    }
    metadataEntity.setId(entityId);
    metadataEntity.setName(entityName);
    metadataEntity.setExternalId(externalId);
    metadataEntity.setClassEntity(metadataClass);
    metadataEntity.setData(data);
    return metadataEntity;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) Folder(com.epam.pipeline.entity.pipeline.Folder)

Example 18 with MetadataClass

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

the class MetadataEntityManager method deleteMetadataClass.

@Transactional(propagation = Propagation.REQUIRED)
public MetadataClass deleteMetadataClass(Long id) {
    Assert.notNull(id, messageHelper.getMessage(MessageConstants.ERROR_INVALID_METADATA_ENTITY_CLASS_ID, id));
    MetadataClass metadataClass = loadClass(id);
    metadataClassDao.deleteMetadataClass(id);
    return metadataClass;
}
Also used : MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with MetadataClass

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

the class MetadataEntityManager method updateExternalClassName.

@Transactional(propagation = Propagation.REQUIRED)
public MetadataClass updateExternalClassName(Long id, FireCloudClass externalClassName) {
    Assert.notNull(id, messageHelper.getMessage(MessageConstants.ERROR_INVALID_METADATA_ENTITY_CLASS_ID, id));
    MetadataClass metadataClass = loadClass(id);
    Assert.notNull(metadataClass, messageHelper.getMessage(MessageConstants.ERROR_METADATA_ENTITY_CLASS_NOT_FOUND, id));
    metadataClass.setFireCloudClassName(externalClassName);
    metadataClassDao.updateMetadataClass(metadataClass);
    return metadataClass;
}
Also used : MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with MetadataClass

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

the class MetadataUploadManager method readFile.

private MetadataParsingResult readFile(Long parentId, MultipartFile file) {
    try {
        final Folder parent = folderManager.load(parentId);
        String delimiter = MetadataParsingUtils.getDelimiterFromFileExtension(file.getOriginalFilename());
        byte[] inputData = file.getBytes();
        MetadataHeader header = new MetadataEntityHeaderParser(delimiter).readHeader(ByteSource.wrap(inputData).openStream());
        validateTypes(header, parentId);
        MetadataClass metadataClass = getOrCreateClass(header.getClassName());
        return new MetadataEntityReader(delimiter, parent, metadataClass).readData(ByteSource.wrap(inputData).openStream(), header.getFields());
    } catch (IOException e) {
        throw new MetadataReadingException(e.getMessage(), e);
    }
}
Also used : MetadataEntityReader(com.epam.pipeline.manager.metadata.parser.MetadataEntityReader) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) MetadataReadingException(com.epam.pipeline.exception.MetadataReadingException) MetadataHeader(com.epam.pipeline.manager.metadata.parser.MetadataHeader) IOException(java.io.IOException) Folder(com.epam.pipeline.entity.pipeline.Folder) MetadataEntityHeaderParser(com.epam.pipeline.manager.metadata.parser.MetadataEntityHeaderParser)

Aggregations

MetadataClass (com.epam.pipeline.entity.metadata.MetadataClass)25 Folder (com.epam.pipeline.entity.pipeline.Folder)11 MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)10 Transactional (org.springframework.transaction.annotation.Transactional)10 Test (org.junit.Test)7 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)6 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)5 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)3 MetadataReadingException (com.epam.pipeline.exception.MetadataReadingException)3 IOException (java.io.IOException)3 com.epam.pipeline.manager.metadata.parser (com.epam.pipeline.manager.metadata.parser)2 FolderManager (com.epam.pipeline.manager.pipeline.FolderManager)2 AuthManager (com.epam.pipeline.manager.security.AuthManager)2 MetadataParsingUtils (com.epam.pipeline.manager.utils.MetadataParsingUtils)2 InputStream (java.io.InputStream)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Test (org.junit.jupiter.api.Test)2