use of com.epam.pipeline.entity.metadata.MetadataEntity 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.MetadataEntity 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.MetadataEntity in project cloud-pipeline by epam.
the class GrantPermissionManager method metadataEntityPermission.
public boolean metadataEntityPermission(Long entityId, String permissionName) {
MetadataEntity entity = metadataEntityManager.load(entityId);
if (entity.getParent() == null || entity.getParent().getId() == null) {
return isAdmin(getSids());
}
AbstractSecuredEntity securedEntity = entityManager.load(AclClass.FOLDER, entity.getParent().getId());
return permissionsHelper.isAllowed(permissionName, securedEntity);
}
use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.
the class ObjectCreatorUtils method createMetadataEntity.
public static MetadataEntity createMetadataEntity(Folder folder, MetadataClass metadataClass, String name, String externalId, Map<String, PipeConfValue> data) {
MetadataEntity metadataEntity = new MetadataEntity();
metadataEntity.setName(name);
metadataEntity.setClassEntity(metadataClass);
metadataEntity.setExternalId(externalId);
metadataEntity.setParent(folder);
metadataEntity.setData(data);
return metadataEntity;
}
use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.
the class FolderEventServiceTest method shouldAddFolderEvent.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void shouldAddFolderEvent() {
doNothing().when(entityManager).setManagers(anyListOf(SecuredEntityManager.class));
Folder folder2 = new Folder(2L);
Pipeline pipeline = new Pipeline(1L);
S3bucketDataStorage dataStorage = new S3bucketDataStorage(1L, "", "");
RunConfiguration runConfiguration = new RunConfiguration();
runConfiguration.setId(1L);
MetadataEntity metadataEntity = new MetadataEntity();
metadataEntity.setClassEntity(new MetadataClass(1L, METADATA_CLASS_NAME));
metadataEntity.setId(1L);
Folder folder1 = new Folder(1L);
folder1.setChildFolders(Collections.singletonList(folder2));
folder1.setPipelines(Collections.singletonList(pipeline));
folder1.setStorages(Collections.singletonList(dataStorage));
folder1.setConfigurations(Collections.singletonList(runConfiguration));
folder1.setMetadata(Collections.singletonMap(METADATA_CLASS_NAME, 1));
when(issueManager.loadIssuesForEntity(any())).thenReturn(Arrays.asList(Issue.builder().id(1L).build(), Issue.builder().id(2L).build()));
when(pipelineRunManager.loadAllRunsByPipeline(anyLong())).thenReturn(Arrays.asList(new PipelineRun(1L, ""), new PipelineRun(2L, "")));
when(dataStorageManager.load(1L)).thenReturn(dataStorage);
when(folderManager.load(1L)).thenReturn(folder1);
when(folderManager.load(2L)).thenReturn(folder2);
when(metadataEntityManager.loadMetadataEntityByClassNameAndFolderId(anyLong(), anyString())).thenReturn(Collections.singletonList(metadataEntity));
doNothing().when(eventDao).insertUpdateEvent(anyString(), anyLong());
folderEventService.updateEventsWithChildrenAndIssues(1L);
verify(eventDao).insertUpdateEvent("folder", 1L);
verify(eventDao).insertUpdateEvent("folder", 2L);
verify(eventDao).insertUpdateEvent("pipeline", 1L);
verify(eventDao).insertUpdateEvent("run", 1L);
verify(eventDao).insertUpdateEvent("run", 2L);
verify(eventDao).insertUpdateEvent("S3", 1L);
verify(eventDao).insertUpdateEvent("configuration", 1L);
verify(eventDao).insertUpdateEvent("metadata_entity", 1L);
verify(eventDao, times(6)).insertUpdateEvent("issue", 1L);
verify(eventDao, times(6)).insertUpdateEvent("issue", 2L);
verifyNoMoreInteractions(eventDao);
}
Aggregations