use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.
the class MetadataDownloadManager method getInputStream.
public InputStream getInputStream(final Long folderId, final String entityClass, final String fileExtension) {
final MetadataFileFormat fileFormat = retrieveMetadataFileFormat(fileExtension);
final List<MetadataEntity> entities = retrieveMetadataEntities(folderId, entityClass);
final StringWriter stringWriter = new StringWriter();
final MetadataWriter metadataWriter = metadataWriterProvider.getMetadataWriter(stringWriter, fileFormat);
metadataWriter.writeEntities(entityClass, entities);
try {
return new StringInputStream(stringWriter.toString());
} catch (IOException e) {
throw new MetadataWriterException(messageHelper.getMessage(MessageConstants.ERROR_METADATA_ENTITY_WRITING_BAD_ENCODING), e);
}
}
use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.
the class MetadataEntityManager method getCommonFolderForEntities.
private Long getCommonFolderForEntities(Set<MetadataEntity> metadataEntities) {
if (CollectionUtils.isEmpty(metadataEntities)) {
return null;
}
MetadataEntity metadataEntity = metadataEntities.stream().findFirst().orElseThrow(() -> new IllegalArgumentException("Cannot determine folder for entities."));
Long folderId = metadataEntity.getParent().getId();
Assert.isTrue(metadataEntities.stream().allMatch(entity -> Objects.equals(folderId, entity.getParent().getId())), messageHelper.getMessage(MessageConstants.ERROR_FOLDER_INVALID_ID));
return folderId;
}
use of com.epam.pipeline.entity.metadata.MetadataEntity 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.MetadataEntity in project cloud-pipeline by epam.
the class MetadataEntityManager method updateMetadataEntity.
@Transactional(propagation = Propagation.REQUIRED)
public MetadataEntity updateMetadataEntity(MetadataEntityVO metadataEntityVO) {
Assert.notNull(metadataEntityVO.getParentId(), messageHelper.getMessage(MessageConstants.ERROR_PARENT_REQUIRED));
MetadataEntity metadataEntity = metadataEntityVO.convertToMetadataEntity();
if (metadataEntity.getParent() != null) {
folderManager.load(metadataEntity.getParent().getId());
}
Long entityId = metadataEntity.getId();
if (entityId != null) {
MetadataEntity existingMetadataEntity = existingMetadataItem(entityId, false);
if (existingMetadataEntity != null) {
metadataEntityDao.updateMetadataEntity(metadataEntity);
return metadataEntity;
}
LOGGER.debug("Metadata entity with id %d was not found. A new one will be created.", entityId);
}
metadataEntityDao.createMetadataEntity(metadataEntity);
return metadataEntity;
}
use of com.epam.pipeline.entity.metadata.MetadataEntity in project cloud-pipeline by epam.
the class ParameterMapper method resolveParameters.
/**
* Gets configuration for a list of {@link AbstractRunConfigurationEntry} resolving
* template parameters from
* @param entity to use for parameters template mapping
* @param entries to resolve
* @param projectData metadata of associated project {@link com.epam.pipeline.entity.pipeline.Folder}
* @return configuration for all input entries
*/
public ResolvedConfiguration resolveParameters(MetadataEntity entity, List<? extends AbstractRunConfigurationEntry> entries, Map<String, PipeConfValue> projectData) {
if (CollectionUtils.isEmpty(entries)) {
return new ResolvedConfiguration(entity, Collections.emptyMap());
}
if (entity == null) {
return new ResolvedConfiguration(null, entries.stream().collect(Collectors.toMap(AbstractRunConfigurationEntry::getName, this::getEntryConfiguration)));
}
Map<MetadataKey, MetadataEntity> entityReferences = loadReferences(entity);
Map<String, PipelineConfiguration> resolved = new HashMap<>();
entries.forEach(entry -> {
checkClassIdMatch(entity, entry.getRootEntityId());
PipelineConfiguration configuration = getEntryConfiguration(entry);
if (MapUtils.isNotEmpty(configuration.getParameters())) {
configuration.setParameters(mapParameters(entity, projectData, configuration.getParameters(), entityReferences));
}
resolved.put(entry.getName(), configuration);
});
return new ResolvedConfiguration(entity, resolved);
}
Aggregations