Search in sources :

Example 31 with MetadataEntity

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

the class MetadataEntityVO method convertToMetadataEntity.

public MetadataEntity convertToMetadataEntity() {
    MetadataEntity metadataEntity = new MetadataEntity();
    MetadataClass metadataClass = new MetadataClass();
    metadataClass.setId(classId);
    metadataClass.setName(className);
    if (parentId != null) {
        metadataEntity.setParent(new Folder(parentId));
    }
    metadataEntity.setId(entityId);
    metadataEntity.setName(entityName);
    metadataEntity.setExternalId(externalId);
    metadataEntity.setClassEntity(metadataClass);
    metadataEntity.setData(data);
    return metadataEntity;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) Folder(com.epam.pipeline.entity.pipeline.Folder)

Example 32 with MetadataEntity

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

the class MetadataEntityDao method batchUpdate.

@Transactional(propagation = Propagation.MANDATORY)
@SuppressWarnings("unchecked")
public Collection<MetadataEntity> batchUpdate(List<MetadataEntity> entitiesToUpdate) {
    for (int i = 0; i < entitiesToUpdate.size(); i += BATCH_SIZE) {
        final List<MetadataEntity> batchList = entitiesToUpdate.subList(i, i + BATCH_SIZE > entitiesToUpdate.size() ? entitiesToUpdate.size() : i + BATCH_SIZE);
        Map<String, Object>[] batchValues = new Map[batchList.size()];
        for (int j = 0; j < batchList.size(); j++) {
            MetadataEntity entity = batchList.get(j);
            batchValues[j] = MetadataEntityParameters.getParameters(entity).getValues();
        }
        getNamedParameterJdbcTemplate().batchUpdate(this.updateMetadataEntityQuery, batchValues);
    }
    return entitiesToUpdate;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) HashMap(java.util.HashMap) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with MetadataEntity

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

the class MetadataEntityManager method createAndUpdateEntities.

@Transactional(propagation = Propagation.REQUIRED)
public List<MetadataEntity> createAndUpdateEntities(Long parentId, MetadataParsingResult parsedData) {
    checkUploadIntegrity(parsedData.getReferences(), parentId);
    Map<String, MetadataEntity> existing = getExistingEntities(parsedData.getEntities().keySet(), parentId, parsedData.getMetadataClass().getName()).stream().collect(Collectors.toMap(MetadataEntity::getExternalId, Function.identity()));
    List<MetadataEntity> entitiesToUpdate = new ArrayList<>();
    List<MetadataEntity> entitiesToCreate = new ArrayList<>();
    parsedData.getEntities().values().forEach(e -> {
        if (existing.containsKey(e.getExternalId())) {
            MetadataEntity current = existing.get(e.getExternalId());
            if (org.apache.commons.lang3.StringUtils.isNotBlank(e.getName())) {
                current.setName(e.getName());
            }
            current.getData().putAll(e.getData());
            entitiesToUpdate.add(current);
        } else {
            entitiesToCreate.add(e);
        }
    });
    List<MetadataEntity> result = new ArrayList<>(entitiesToCreate.size() + entitiesToUpdate.size());
    result.addAll(metadataEntityDao.batchInsert(entitiesToCreate));
    result.addAll(metadataEntityDao.batchUpdate(entitiesToUpdate));
    return result;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with MetadataEntity

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

the class MetadataEntityManager method deleteMetadataItemKey.

@Transactional(propagation = Propagation.REQUIRED)
public MetadataEntity deleteMetadataItemKey(Long id, String key) {
    MetadataEntity existingMetadataEntity = existingMetadataItem(id, true);
    existingMetadataEntity.getData().keySet().remove(key);
    metadataEntityDao.deleteMetadataItemKey(existingMetadataEntity.getId(), key);
    return existingMetadataEntity;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with MetadataEntity

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

the class MetadataEntityManager method deleteMetadataEntity.

@Transactional(propagation = Propagation.REQUIRED)
public MetadataEntity deleteMetadataEntity(Long id) {
    Assert.notNull(id, messageHelper.getMessage(MessageConstants.ERROR_INVALID_METADATA_ENTITY_ID, id));
    MetadataEntity metadataEntity = metadataEntityDao.loadMetadataEntityById(id);
    Assert.notNull(metadataEntity, messageHelper.getMessage(MessageConstants.ERROR_METADATA_ENTITY_NOT_FOUND, id));
    metadataEntityDao.deleteMetadataEntity(metadataEntity.getId());
    return metadataEntity;
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) Transactional(org.springframework.transaction.annotation.Transactional)

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