Search in sources :

Example 1 with MetadataEntity

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);
    }
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) StringInputStream(com.amazonaws.util.StringInputStream) StringWriter(java.io.StringWriter) MetadataWriterException(com.epam.pipeline.manager.metadata.writer.MetadataWriterException) IOException(java.io.IOException) MetadataWriter(com.epam.pipeline.manager.metadata.writer.MetadataWriter) MetadataFileFormat(com.epam.pipeline.manager.metadata.writer.MetadataFileFormat)

Example 2 with MetadataEntity

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;
}
Also used : MetadataClassDescription(com.epam.pipeline.entity.metadata.MetadataClassDescription) EntityTypeField(com.epam.pipeline.manager.metadata.parser.EntityTypeField) MessageConstants(com.epam.pipeline.common.MessageConstants) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) MetadataField(com.epam.pipeline.entity.metadata.MetadataField) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MessageHelper(com.epam.pipeline.common.MessageHelper) FireCloudClass(com.epam.pipeline.entity.metadata.FireCloudClass) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) Map(java.util.Map) MetadataParsingResult(com.epam.pipeline.manager.metadata.parser.MetadataParsingResult) SecuredEntityManager(com.epam.pipeline.manager.security.SecuredEntityManager) MetadataEntityVO(com.epam.pipeline.controller.vo.metadata.MetadataEntityVO) MetadataEntityConverter(com.epam.pipeline.manager.metadata.parser.MetadataEntityConverter) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) Logger(org.slf4j.Logger) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) Collection(java.util.Collection) Set(java.util.Set) PagedResult(com.epam.pipeline.controller.PagedResult) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) MetadataEntityDao(com.epam.pipeline.dao.metadata.MetadataEntityDao) List(java.util.List) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) NumberUtils(org.apache.commons.lang3.math.NumberUtils) AclClass(com.epam.pipeline.entity.security.acl.AclClass) MetadataClassDao(com.epam.pipeline.dao.metadata.MetadataClassDao) MetadataFilter(com.epam.pipeline.entity.metadata.MetadataFilter) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity)

Example 3 with MetadataEntity

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());
}
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 4 with MetadataEntity

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;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with 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);
}
Also used : ResolvedConfiguration(com.epam.pipeline.entity.pipeline.ResolvedConfiguration) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) HashMap(java.util.HashMap) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration)

Aggregations

MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)48 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)22 Test (org.junit.Test)22 Transactional (org.springframework.transaction.annotation.Transactional)14 MetadataClass (com.epam.pipeline.entity.metadata.MetadataClass)12 Folder (com.epam.pipeline.entity.pipeline.Folder)10 HashMap (java.util.HashMap)9 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)7 List (java.util.List)7 Map (java.util.Map)6 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)5 IOException (java.io.IOException)5 MetadataReadingException (com.epam.pipeline.exception.MetadataReadingException)4 FolderManager (com.epam.pipeline.manager.pipeline.FolderManager)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Propagation (org.springframework.transaction.annotation.Propagation)4 AclClass (com.epam.pipeline.entity.security.acl.AclClass)3 com.epam.pipeline.manager.metadata.parser (com.epam.pipeline.manager.metadata.parser)3