Search in sources :

Example 36 with MetadataEntity

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

Example 37 with MetadataEntity

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

the class EntityLineProcessor method getOrCreateEntity.

private MetadataEntity getOrCreateEntity(String id) {
    MetadataEntity entity = currentResults.get(id);
    if (entity == null) {
        entity = new MetadataEntity();
        entity.setExternalId(id);
        entity.setParent(parent);
        entity.setClassEntity(metadataClass);
        entity.setData(new HashMap<>());
        currentResults.put(id, entity);
    }
    return entity;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity)

Example 38 with MetadataEntity

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

the class MetadataEntityConverter method convert.

public static Map<String, String> convert(List<MetadataEntity> entities) {
    Map<FireCloudClass, FireCloudData> content = new EnumMap<>(FireCloudClass.class);
    entities.forEach(entity -> {
        FireCloudClass fireCloudClass = entity.getClassEntity().getFireCloudClassName();
        Assert.notNull(fireCloudClass, "Fire Cloud class must be specified.");
        FireCloudData dataContent = content.computeIfAbsent(fireCloudClass, key -> new FireCloudData(fireCloudClass, entity.getData()));
        dataContent.put(entity);
    });
    Map<String, String> result = new HashMap<>();
    content.forEach(((fireCloudClass, fireCloudData) -> {
        result.put(fireCloudClass.getFileName(), fireCloudData.getContent());
        if (fireCloudData.isSet()) {
            result.put(fireCloudClass.getMembershipFileName(), fireCloudData.getMembershipContent());
        }
    }));
    return result;
}
Also used : List(java.util.List) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) FireCloudClass(com.epam.pipeline.entity.metadata.FireCloudClass) EnumMap(java.util.EnumMap) Map(java.util.Map) HashMap(java.util.HashMap) Assert(org.springframework.util.Assert) HashMap(java.util.HashMap) FireCloudClass(com.epam.pipeline.entity.metadata.FireCloudClass) EnumMap(java.util.EnumMap)

Example 39 with MetadataEntity

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

the class FolderDaoTest method testCreateAndLoadFolderWithMetadata.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testCreateAndLoadFolderWithMetadata() {
    Folder folder = getFolder();
    // create
    folderDao.createFolder(folder);
    Map<String, Integer> metadata = new HashMap<>();
    metadata.put(CLASS_NAME_1, 1);
    folder.setMetadata(metadata);
    // add metadata
    MetadataEntity metadataEntity = new MetadataEntity();
    metadataEntity.setName(TEST_ENTITY_NAME_1);
    MetadataClass metadataClass = createMetadataClass();
    metadataEntity.setClassEntity(metadataClass);
    metadataEntity.setParent(folder);
    Map<String, PipeConfValue> data = new HashMap<>();
    data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    metadataEntity.setData(data);
    metadataEntityDao.createMetadataEntity(metadataEntity);
    Folder loaded = folderDao.loadFolder(folder.getId());
    assertEquals(folder.getId(), loaded.getId());
    assertEquals(folder.getName(), loaded.getName());
    assertEquals(folder.getMetadata(), loaded.getMetadata());
    assertNull(folder.getParentId());
    Map<String, Integer> loadedMetadata = loaded.getMetadata();
    assertTrue(!loadedMetadata.isEmpty() && loadedMetadata.size() == 1);
    assertEquals(metadataEntity.getClassEntity().getName(), loadedMetadata.keySet().toArray()[0]);
    assertEquals(1, loadedMetadata.get(CLASS_NAME_1).intValue());
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) Folder(com.epam.pipeline.entity.pipeline.Folder) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with MetadataEntity

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

the class MetadataEntityConverterTest method shouldFailIfPairWithoutParticipantAttribute.

@Test(expected = IllegalArgumentException.class)
public void shouldFailIfPairWithoutParticipantAttribute() {
    Map<String, PipeConfValue> pairData = new HashMap<>();
    pairData.put(CASE_SAMPLE_ARGUMENT, new PipeConfValue(SAMPLE_ATTRIBUTE_TYPE, SAMPLE_ENTITY_ID2));
    pairData.put(CONTROL_SAMPLE_ARGUMENT, new PipeConfValue(SAMPLE_ATTRIBUTE_TYPE, SAMPLE_ENTITY_ID1));
    MetadataEntity pair = getEntity(pairClass, PAIR_ENTITY_ID1, pairData);
    MetadataEntityConverter.convert(Collections.singletonList(pair));
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) Test(org.junit.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