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