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");
}
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);
}
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);
}
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);
}
}
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()));
}
Aggregations