Search in sources :

Example 26 with EntityVO

use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.

the class MetadataDaoTest method testShouldSearchMetadataByClassAndKeyValuePair.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testShouldSearchMetadataByClassAndKeyValuePair() {
    EntityVO entityVO = new EntityVO(ID_1, CLASS_1);
    Map<String, PipeConfValue> data = new HashMap<>();
    data.put(DATA_KEY_1, new PipeConfValue(null, DATA_VALUE_1));
    data.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_1));
    MetadataEntry metadataToSave = new MetadataEntry();
    metadataToSave.setEntity(entityVO);
    metadataToSave.setData(data);
    metadataDao.registerMetadataItem(metadataToSave);
    EntityVO entityVO2 = new EntityVO(ID_1, CLASS_2);
    metadataToSave.setEntity(entityVO2);
    metadataToSave.setData(data);
    metadataDao.registerMetadataItem(metadataToSave);
    List<EntityVO> loadedEntities = metadataDao.searchMetadataByClassAndKeyValue(CLASS_1, Collections.singletonMap(DATA_KEY_1, new PipeConfValue(null, DATA_VALUE_1)));
    Assert.assertEquals(1, loadedEntities.size());
    Assert.assertEquals(entityVO, loadedEntities.get(0));
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) HashMap(java.util.HashMap) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with EntityVO

use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.

the class MetadataDaoTest method testOneMetadata.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testOneMetadata() {
    EntityVO entityVO = new EntityVO(ID_1, CLASS_1);
    Map<String, PipeConfValue> data = new HashMap<>();
    data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    MetadataEntry metadataToSave = new MetadataEntry();
    metadataToSave.setEntity(entityVO);
    metadataToSave.setData(data);
    // metadata registration
    metadataDao.registerMetadataItem(metadataToSave);
    MetadataEntry createdMetadata = metadataDao.loadMetadataItem(entityVO);
    Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
    Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
    Assert.assertEquals(data, createdMetadata.getData());
    // add key to metadata
    data.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_2));
    metadataDao.uploadMetadataItemKey(entityVO, DATA_KEY_2, DATA_VALUE_2, DATA_TYPE_2);
    createdMetadata = metadataDao.loadMetadataItem(entityVO);
    Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
    Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
    Assert.assertEquals(data, createdMetadata.getData());
    // delete key from metadata
    data.clear();
    data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    metadataDao.deleteMetadataItemKey(entityVO, DATA_KEY_2);
    createdMetadata = metadataDao.loadMetadataItem(entityVO);
    Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
    Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
    Assert.assertEquals(data, createdMetadata.getData());
    // update metadata
    data.clear();
    data.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_2));
    metadataToSave.setData(data);
    metadataDao.uploadMetadataItem(metadataToSave);
    createdMetadata = metadataDao.loadMetadataItem(entityVO);
    Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
    Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
    Assert.assertEquals(data, createdMetadata.getData());
    // delete several keys from metadata
    data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    data.put(DATA_KEY_3, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_1));
    metadataToSave.setData(data);
    Set<String> keysToDelete = new HashSet<>();
    keysToDelete.add(DATA_KEY_1);
    keysToDelete.add(DATA_KEY_3);
    keysToDelete.add(NON_EXISTING_DATA_KEY);
    metadataDao.deleteMetadataItemKeys(metadataToSave, keysToDelete);
    createdMetadata = metadataDao.loadMetadataItem(entityVO);
    Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
    Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
    data.remove(DATA_KEY_1);
    data.remove(DATA_KEY_3);
    Assert.assertEquals(data, createdMetadata.getData());
    // delete metadata
    metadataDao.deleteMetadataItem(entityVO);
    createdMetadata = metadataDao.loadMetadataItem(entityVO);
    Assert.assertNull(createdMetadata);
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) HashMap(java.util.HashMap) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) HashSet(java.util.HashSet) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with EntityVO

use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.

the class MetadataDaoTest method testListMetadata.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testListMetadata() {
    EntityVO entity1 = new EntityVO(ID_1, CLASS_1);
    Map<String, PipeConfValue> data1 = new HashMap<>();
    data1.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    MetadataEntry metadataToSave1 = new MetadataEntry();
    metadataToSave1.setEntity(entity1);
    metadataToSave1.setData(data1);
    EntityVO entity2 = new EntityVO(ID_2, CLASS_2);
    Map<String, PipeConfValue> data2 = new HashMap<>();
    data2.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_2));
    MetadataEntry metadataToSave2 = new MetadataEntry();
    metadataToSave2.setEntity(entity2);
    metadataToSave2.setData(data2);
    metadataDao.registerMetadataItem(metadataToSave1);
    metadataDao.registerMetadataItem(metadataToSave2);
    List<EntityVO> entities = new ArrayList<>();
    entities.add(entity1);
    entities.add(entity2);
    List<MetadataEntry> metadataEntries = new ArrayList<>();
    metadataEntries.add(metadataToSave1);
    metadataEntries.add(metadataToSave2);
    List<MetadataEntry> createdMetadata = metadataDao.loadMetadataItems(entities);
    Assert.assertEquals(metadataEntries, createdMetadata);
    metadataDao.deleteMetadataItem(entity1);
    metadataDao.deleteMetadataItem(entity2);
    createdMetadata = metadataDao.loadMetadataItems(entities);
    Assert.assertNull(createdMetadata);
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) HashMap(java.util.HashMap) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) ArrayList(java.util.ArrayList) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with EntityVO

use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.

the class MetadataDaoTest method createItems.

private Pair<EntityVO, MetadataEntry> createItems(String issueName, AclClass aclClass, boolean createMetadata) {
    EntityVO entity = new EntityVO(1L, aclClass);
    Issue issue = getIssue(issueName, entity);
    issueDao.createIssue(issue);
    MetadataEntry metadataEntry = new MetadataEntry();
    if (createMetadata) {
        metadataEntry.setEntity(entity);
        metadataEntry.setData(new HashMap<>());
        metadataDao.registerMetadataItem(metadataEntry);
    }
    return new ImmutablePair<>(entity, metadataEntry);
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Issue(com.epam.pipeline.entity.issue.Issue) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry)

Example 30 with EntityVO

use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.

the class FolderDaoTest method createObjectMetadata.

private List<FolderWithMetadata> createObjectMetadata(List<Folder> folders) {
    Map<String, PipeConfValue> data = new HashMap<>();
    data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    MetadataEntry metadataToSave = new MetadataEntry();
    List<FolderWithMetadata> foldersWithMetadata = new ArrayList<>();
    folders.forEach(folder -> {
        metadataToSave.setEntity(new EntityVO(folder.getId(), AclClass.FOLDER));
        metadataToSave.setData(data);
        metadataDao.registerMetadataItem(metadataToSave);
        FolderWithMetadata folderWithMetadata = convertToFolderWithMetadata(folder);
        folderWithMetadata.setData(data);
        foldersWithMetadata.add(folderWithMetadata);
    });
    return foldersWithMetadata;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata)

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