Search in sources :

Example 21 with PipeConfValue

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

the class MetadataLineProcessor method processLine.

@Override
public boolean processLine(String line) {
    if (StringUtils.isEmpty(line)) {
        return false;
    }
    if (!headerProcessed) {
        headerProcessed = true;
        String[] splitted = StringUtils.split(line, delimiter);
        for (int i = 0; i < splitted.length; i++) {
            MetadataColumnTypes type = getColumnType(splitted[i].toUpperCase());
            indexes.put(type.name(), i);
        }
    } else {
        String[] splitted = StringUtils.splitPreserveAllTokens(line, delimiter);
        if (splitted.length > 3 || splitted.length < 2) {
            throw new IllegalArgumentException("Cannot parse line: incorrect length.");
        }
        String key = splitted[indexes.get(MetadataColumnTypes.KEY.name())];
        String value = splitted[indexes.get(MetadataColumnTypes.VALUE.name())];
        String type = splitted.length == 2 ? "string" : splitted[indexes.get(MetadataColumnTypes.TYPE.name())];
        result.put(key, new PipeConfValue(type, value));
    }
    return true;
}
Also used : PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue)

Example 22 with PipeConfValue

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

the class FolderManager method loadAllProjects.

public Folder loadAllProjects() {
    Folder root = new Folder();
    Set<Pair<String, String>> indicator = parseProjectIndicator();
    Map<String, PipeConfValue> projectAttributes = indicator.stream().collect(Collectors.toMap(Pair::getLeft, pair -> new PipeConfValue(null, pair.getRight())));
    if (MapUtils.isEmpty(projectAttributes)) {
        return root;
    }
    List<Folder> projects = folderDao.loadAllProjects(projectAttributes).stream().filter(folder -> {
        if (folder instanceof FolderWithMetadata) {
            FolderWithMetadata folderWithMetadata = (FolderWithMetadata) folder;
            Map<String, PipeConfValue> attributes = folderWithMetadata.getData();
            return containsProjectIndicator(indicator, attributes);
        }
        return false;
    }).collect(Collectors.toList());
    root.setChildFolders(projects);
    return root;
}
Also used : MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) Arrays(java.util.Arrays) MessageConstants(com.epam.pipeline.common.MessageConstants) AbstractHierarchicalEntity(com.epam.pipeline.entity.AbstractHierarchicalEntity) LoggerFactory(org.slf4j.LoggerFactory) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) MetadataEntryMapper(com.epam.pipeline.mapper.MetadataEntryMapper) Function(java.util.function.Function) ArrayList(java.util.ArrayList) MetadataManager(com.epam.pipeline.manager.metadata.MetadataManager) Value(org.springframework.beans.factory.annotation.Value) Folder(com.epam.pipeline.entity.pipeline.Folder) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MessageHelper(com.epam.pipeline.common.MessageHelper) Pair(org.apache.commons.lang3.tuple.Pair) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) Map(java.util.Map) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata) GrantPermissionManager(com.epam.pipeline.manager.security.GrantPermissionManager) AbstractRunConfigurationMapper(com.epam.pipeline.mapper.AbstractRunConfigurationMapper) FolderDao(com.epam.pipeline.dao.pipeline.FolderDao) EntityManager(com.epam.pipeline.manager.EntityManager) MapUtils(org.apache.commons.collections4.MapUtils) BaseEntity(com.epam.pipeline.entity.BaseEntity) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) Set(java.util.Set) AbstractDataStorageMapper(com.epam.pipeline.mapper.AbstractDataStorageMapper) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RunConfiguration(com.epam.pipeline.entity.configuration.RunConfiguration) List(java.util.List) MetadataEntityManager(com.epam.pipeline.manager.metadata.MetadataEntityManager) AclClass(com.epam.pipeline.entity.security.acl.AclClass) RunConfigurationManager(com.epam.pipeline.manager.configuration.RunConfigurationManager) Collections(java.util.Collections) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) EntityVO(com.epam.pipeline.controller.vo.EntityVO) Transactional(org.springframework.transaction.annotation.Transactional) StringUtils(org.springframework.util.StringUtils) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Folder(com.epam.pipeline.entity.pipeline.Folder) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata)

Example 23 with PipeConfValue

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

the class FolderManager method getProjectFolder.

FolderWithMetadata getProjectFolder(Map<Long, FolderWithMetadata> folders, Long id, Set<Pair<String, String>> projectIndicators) {
    FolderWithMetadata folder = folders.get(id);
    if (folder == null) {
        return null;
    }
    Map<String, PipeConfValue> metadata = folder.getData();
    if (MapUtils.isEmpty(metadata)) {
        LOGGER.debug("Can not detect project folder: metadata not found.");
        return continueSearch(folders, projectIndicators, folder);
    }
    if (containsProjectIndicator(projectIndicators, metadata)) {
        return folder;
    }
    return continueSearch(folders, projectIndicators, folder);
}
Also used : PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata)

Example 24 with PipeConfValue

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

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

Aggregations

PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)41 Test (org.junit.Test)24 MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)21 HashMap (java.util.HashMap)11 Transactional (org.springframework.transaction.annotation.Transactional)11 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)9 EntityVO (com.epam.pipeline.controller.vo.EntityVO)9 Folder (com.epam.pipeline.entity.pipeline.Folder)9 MetadataEntry (com.epam.pipeline.entity.metadata.MetadataEntry)8 FolderWithMetadata (com.epam.pipeline.entity.metadata.FolderWithMetadata)5 MetadataClass (com.epam.pipeline.entity.metadata.MetadataClass)5 PasswordGenerator.generateRandomString (com.epam.pipeline.utils.PasswordGenerator.generateRandomString)5 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)3 MessageConstants (com.epam.pipeline.common.MessageConstants)2 MessageHelper (com.epam.pipeline.common.MessageHelper)2 MetadataVO (com.epam.pipeline.controller.vo.MetadataVO)2 BaseEntity (com.epam.pipeline.entity.BaseEntity)2