Search in sources :

Example 1 with PipeConfValue

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

the class MetadataEntityManager method updateMetadataItemKey.

@Transactional(propagation = Propagation.REQUIRED)
public MetadataEntity updateMetadataItemKey(MetadataEntityVO metadataEntityVO) {
    MetadataEntity metadataEntity = metadataEntityVO.convertToMetadataEntity();
    Long entityId = metadataEntity.getId();
    MetadataEntity dbEntity = load(entityId);
    Assert.notNull(dbEntity, messageHelper.getMessage(MessageConstants.ERROR_METADATA_ENTITY_NOT_FOUND, dbEntity));
    Assert.notNull(metadataEntity.getData(), messageHelper.getMessage(MessageConstants.ERROR_METADATA_UPDATE_KEY_NOT_FOUND, 0));
    Assert.isTrue(metadataEntity.getData().size() == 1, messageHelper.getMessage(MessageConstants.ERROR_METADATA_UPDATE_KEY_NOT_FOUND, metadataEntity.getData().size()));
    Map.Entry<String, PipeConfValue> metadataEntry = metadataEntity.getData().entrySet().iterator().next();
    metadataEntityDao.updateMetadataEntityDataKey(metadataEntity, metadataEntry.getKey(), metadataEntry.getValue().getValue(), metadataEntry.getValue().getType());
    return metadataEntityDao.loadMetadataEntityById(metadataEntity.getId());
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) HashMap(java.util.HashMap) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with PipeConfValue

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

the class FireCloudData method put.

public void put(MetadataEntity entity) {
    if (entity.getExternalId() == null) {
        throw new IllegalArgumentException(String.format("External ID must be specified for entity ID %s.", entity.getId()));
    }
    if (entity.getClassEntity().getFireCloudClassName() != fireCloudClass) {
        throw new IllegalArgumentException(String.format("Fire Cloud class is invalid: expected %s, but found %s.", fireCloudClass, entity.getClassEntity().getFireCloudClassName()));
    }
    content = String.format(MERGE_LINES_FORMAT, content, entity.getExternalId());
    if (CollectionUtils.isEmpty(entity.getData())) {
        return;
    }
    Map<String, String> data = new HashMap<>();
    int processedColumnCount = 0;
    boolean membershipFilled = false;
    for (Map.Entry<String, PipeConfValue> entry : entity.getData().entrySet()) {
        String name = entry.getKey();
        PipeConfValue confValue = entry.getValue();
        if (!isArrayType(confValue.getType())) {
            checkColumnExistence(entity.getId(), name);
            data.put(name, confValue.getValue());
            processedColumnCount++;
        } else {
            membershipFilled = putMembership(entity, confValue);
        }
    }
    assertSizes(processedColumnCount, columnNames.size());
    checkMembershipFilled(membershipFilled);
    columnNames.forEach(column -> content = String.format(LINE_FORMAT, content, data.get(column)));
}
Also used : HashMap(java.util.HashMap) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with PipeConfValue

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

the class ParameterMapper method resolveReferences.

private List<MetadataEntity> resolveReferences(String reference, String[] fields, Map<MetadataKey, MetadataEntity> entityReferences, MetadataEntity entity, boolean includeLast) {
    List<MetadataEntity> currentEntities = Collections.singletonList(entity);
    int lastIndex = includeLast ? fields.length : fields.length - 1;
    for (int i = 0; i < lastIndex; i++) {
        List<MetadataEntity> links = new ArrayList<>();
        for (MetadataEntity currentEntity : currentEntities) {
            Map<String, PipeConfValue> currentEntityData = currentEntity.getData();
            String field = fields[i];
            if (MapUtils.isEmpty(currentEntityData) || !currentEntityData.containsKey(field)) {
                throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_MISSING_VALUE, reference, field));
            }
            PipeConfValue value = currentEntityData.get(field);
            if (StringUtils.isBlank(value.getValue())) {
                throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_MISSING_VALUE, reference, field));
            }
            String entityClassName = EntityTypeField.parseClass(value.getType());
            if (StringUtils.isBlank(entityClassName)) {
                throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_NON_REFERENCE_TYPE, reference, field));
            }
            if (EntityTypeField.isArrayType(value.getType())) {
                List<String> arrayValues = JsonMapper.parseData(value.getValue(), new TypeReference<List<String>>() {
                });
                if (CollectionUtils.isEmpty(arrayValues)) {
                    throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_INVALID_ARRAY, reference, value.getValue(), field));
                }
                arrayValues.forEach(v -> links.add(getReference(entityReferences, v, entityClassName, reference)));
            } else {
                links.add(getReference(entityReferences, value.getValue(), entityClassName, reference));
            }
        }
        currentEntities = links;
    }
    return currentEntities;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) ArrayList(java.util.ArrayList) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with PipeConfValue

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

the class ParameterMapper method resolveConfigurations.

public List<ResolvedConfiguration> resolveConfigurations(AnalysisConfiguration<? extends AbstractRunConfigurationEntry> configuration) {
    FolderWithMetadata project = folderManager.getProject(configuration.getConfigurationId(), AclClass.CONFIGURATION);
    Map<String, PipeConfValue> projectData = project == null ? new HashMap<>() : project.getData();
    List<? extends AbstractRunConfigurationEntry> entries = configuration.getEntries();
    if (CollectionUtils.isEmpty(configuration.getEntitiesIds())) {
        return Collections.singletonList(resolveParameters(entries, projectData));
    }
    // In case of array references one entity may be expanded to
    // list of references entities, e.g. SampleSet is expanded
    // to list of Sample entities
    // TODO: The only reason to store it as map - is to add association to run
    // TODO: to initial entity, from which link comes. Find better solution.
    Map<Long, List<MetadataEntity>> targetEntities = fetchAndExpandInputEntities(configuration);
    // resolve all parameter references in configurations
    Map<Long, ResolvedConfiguration> resolvedConfigurations = targetEntities.values().stream().flatMap(Collection::stream).collect(Collectors.toMap(BaseEntity::getId, entity -> resolveParameters(entity, entries, projectData)));
    return targetEntities.entrySet().stream().map(idToEntities -> idToEntities.getValue().stream().map(entity -> {
        ResolvedConfiguration currentConfiguration = resolvedConfigurations.get(entity.getId());
        currentConfiguration.getAssociatedEntityIds().add(idToEntities.getKey());
        return currentConfiguration;
    }).collect(Collectors.toList())).flatMap(Collection::stream).collect(Collectors.toList());
}
Also used : EntityTypeField(com.epam.pipeline.manager.metadata.parser.EntityTypeField) Setter(lombok.Setter) Getter(lombok.Getter) MessageConstants(com.epam.pipeline.common.MessageConstants) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) PipeConfValueVO(com.epam.pipeline.entity.configuration.PipeConfValueVO) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MessageHelper(com.epam.pipeline.common.MessageHelper) AnalysisConfiguration(com.epam.pipeline.manager.pipeline.runner.AnalysisConfiguration) Service(org.springframework.stereotype.Service) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) MapUtils(org.apache.commons.collections4.MapUtils) BaseEntity(com.epam.pipeline.entity.BaseEntity) Logger(org.slf4j.Logger) Collection(java.util.Collection) JsonMapper(com.epam.pipeline.config.JsonMapper) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) ResolvedConfiguration(com.epam.pipeline.entity.pipeline.ResolvedConfiguration) Objects(java.util.Objects) List(java.util.List) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataEntityManager(com.epam.pipeline.manager.metadata.MetadataEntityManager) AclClass(com.epam.pipeline.entity.security.acl.AclClass) PipelineStart(com.epam.pipeline.entity.pipeline.run.PipelineStart) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) Assert(org.springframework.util.Assert) ResolvedConfiguration(com.epam.pipeline.entity.pipeline.ResolvedConfiguration) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) ArrayList(java.util.ArrayList) List(java.util.List) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata)

Example 5 with PipeConfValue

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

the class MetadataEntityConverterTest method shouldFailIfParticipantSetWithoutParticipants.

@Test(expected = IllegalStateException.class)
public void shouldFailIfParticipantSetWithoutParticipants() {
    Map<String, PipeConfValue> participantSetData = new HashMap<>();
    participantSetData.put(TEST_ARGUMENT1, new PipeConfValue(STRING_TYPE, TEST_VALUE_2));
    MetadataEntity participantSet = getEntity(participantSetClass, "HCC_participants", participantSetData);
    MetadataEntityConverter.convert(Collections.singletonList(participantSet));
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) Test(org.junit.Test)

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