Search in sources :

Example 16 with EntityVO

use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.

the class MetadataManager method updateMetadataItemKeys.

@Transactional(propagation = Propagation.REQUIRED)
public MetadataEntry updateMetadataItemKeys(MetadataVO metadataVO) {
    validateMetadata(metadataVO);
    EntityVO entity = metadataVO.getEntity();
    checkEntityExistence(entity.getEntityId(), entity.getEntityClass());
    MetadataEntry metadataToSave = metadataEntryMapper.toMetadataEntry(metadataVO);
    MetadataEntry existingMetadata = listMetadataItem(metadataToSave.getEntity(), false);
    if (existingMetadata == null) {
        LOGGER.debug("Could not find such metadata. A new one will be created.");
        metadataDao.registerMetadataItem(metadataToSave);
    } else {
        existingMetadata.getData().putAll(metadataToSave.getData());
        metadataDao.uploadMetadataItem(existingMetadata);
    }
    return metadataDao.loadMetadataItem(entity);
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with EntityVO

use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.

the class MetadataManager method findMetadataEntryByNameOrId.

public MetadataEntry findMetadataEntryByNameOrId(String identifier, AclClass entityClass) {
    MetadataEntry metadataEntry = new MetadataEntry();
    EntityVO entity = new EntityVO(loadEntityId(identifier, entityClass), entityClass);
    metadataEntry.setEntity(entity);
    metadataEntry.setData(Collections.emptyMap());
    return metadataEntry;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry)

Example 18 with EntityVO

use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.

the class FolderCrudManager method loadByNameOrId.

/**
 * Tries to find a {@link Folder} entity by some pathOrIdentifier.
 * If identifier is a number, it is interpreted as ID and will be loaded from DB by primary key.
 * Otherwise pathOrIdentifier is interpreted as full path to folder like:
 *      /root/parent/folder-name
 * and method will try to resolve folder hierarchy from this path.
 * @param pathOrIdentifier specifies folder to look for
 * @return {@link Folder} entity if present
 * @throws IllegalArgumentException if {@link Folder} pathOrIdentifier not found
 */
@Override
public Folder loadByNameOrId(String pathOrIdentifier) {
    Folder folder = null;
    String path = pathOrIdentifier;
    try {
        folder = folderDao.loadFolder(Long.parseLong(path));
    } catch (NumberFormatException e) {
        LOGGER.trace(e.getMessage(), e);
    }
    if (folder == null) {
        Long parentId = null;
        if (path.startsWith("/")) {
            path = path.substring(1);
        }
        if (path.endsWith("/")) {
            path = path.substring(0, path.length() - 1);
        }
        String[] pathComponents = path.split("/");
        for (String name : pathComponents) {
            folder = loadByNameAndParentId(name, parentId);
            if (folder == null) {
                break;
            } else {
                parentId = folder.getId();
            }
        }
    }
    Assert.notNull(folder, messageHelper.getMessage(MessageConstants.ERROR_FOLDER_NOT_FOUND, path));
    folder.setHasMetadata(this.metadataManager.hasMetadata(new EntityVO(folder.getId(), AclClass.FOLDER)));
    return folder;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Folder(com.epam.pipeline.entity.pipeline.Folder)

Example 19 with EntityVO

use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.

the class FolderCrudManager method load.

/**
 * Loads {@link Folder} specified by id parameter
 * @param id to find
 * @return {@link Folder} entity if present
 * @throws IllegalArgumentException if {@link Folder} id not found
 */
@Override
public Folder load(Long id) {
    Folder folder = folderDao.loadFolder(id);
    Assert.notNull(folder, messageHelper.getMessage(MessageConstants.ERROR_FOLDER_NOT_FOUND, id));
    folder.setHasMetadata(metadataManager.hasMetadata(new EntityVO(id, AclClass.FOLDER)));
    return folder;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Folder(com.epam.pipeline.entity.pipeline.Folder)

Example 20 with EntityVO

use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.

the class PipelineManager method loadByRepoUrl.

public Pipeline loadByRepoUrl(String url) {
    Optional<Pipeline> loadedPipeline = pipelineDao.loadPipelineByRepoUrl(url);
    Pipeline pipeline = loadedPipeline.orElseThrow(() -> new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_PIPELINE_WITH_URL_NOT_FOUND, url)));
    setCurrentVersion(pipeline);
    pipeline.setHasMetadata(this.metadataManager.hasMetadata(new EntityVO(pipeline.getId(), AclClass.PIPELINE)));
    return pipeline;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Aggregations

EntityVO (com.epam.pipeline.controller.vo.EntityVO)40 Transactional (org.springframework.transaction.annotation.Transactional)22 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)14 Test (org.junit.Test)14 Folder (com.epam.pipeline.entity.pipeline.Folder)13 MetadataEntry (com.epam.pipeline.entity.metadata.MetadataEntry)12 Issue (com.epam.pipeline.entity.issue.Issue)11 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)8 HashMap (java.util.HashMap)5 IssueVO (com.epam.pipeline.controller.vo.IssueVO)4 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)4 Before (org.junit.Before)4 Attachment (com.epam.pipeline.entity.issue.Attachment)3 AclClass (com.epam.pipeline.entity.security.acl.AclClass)3 Date (java.util.Date)3 Map (java.util.Map)3 AfterReturning (org.aspectj.lang.annotation.AfterReturning)3 MetadataVO (com.epam.pipeline.controller.vo.MetadataVO)2 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)2 IssueComment (com.epam.pipeline.entity.issue.IssueComment)2