Search in sources :

Example 1 with CommonDataSourceDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonDataSourceDTO in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeController method createDataSource.

@ApiOperation("Create new data source of datanode.")
@RequestMapping(value = "/api/v1/data-nodes/{dataNodeId}/data-sources", method = RequestMethod.POST)
public JsonResult createDataSource(@PathVariable("dataNodeId") Long id, @RequestBody C_DS_DTO commonDataSourceDTO) throws FieldException, NotExistException, ValidationException, IOException, SolrServerException, NoSuchFieldException, IllegalAccessException, BindException {
    // we validate only two fields, because we don't want to validate another fields, because they always are null
    validate(commonDataSourceDTO);
    JsonResult<CommonDataSourceDTO> result;
    DataNode dataNode = baseDataNodeService.getById(id);
    if (dataNode == null) {
        throw new IllegalArgumentException("Unable to find datanode by ID " + id);
    }
    DS dataSource = convertCommonDataSourceDtoToDataSource(commonDataSourceDTO);
    dataSource.setDataNode(dataNode);
    dataSource = dataSourceService.createOrRestoreDataSource(dataSource);
    result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
    result.setResult(genericConversionService.convert(dataSource, CommonDataSourceDTO.class));
    return result;
}
Also used : CommonDataSourceDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonDataSourceDTO) DataNode(com.odysseusinc.arachne.portal.model.DataNode) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CommonDataSourceDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonDataSourceDTO in project ArachneCentralAPI by OHDSI.

the class BaseDataSourceController method updateDataSource.

private JsonResult<DTO> updateDataSource(Principal principal, Long dataSourceId, DTO commonDataSourceDTO, BindingResult bindingResult) throws PermissionDeniedException, IllegalAccessException, IOException, NoSuchFieldException, SolrServerException, ValidationException {
    JsonResult result;
    if (bindingResult.hasErrors()) {
        result = setValidationErrors(bindingResult);
    } else {
        IUser user = getUser(principal);
        final DS exist = dataSourceService.getNotDeletedByIdInAnyTenant(dataSourceId);
        DS dataSource = convertDTOToDataSource(commonDataSourceDTO);
        dataSource.setId(dataSourceId);
        dataSource.setDataNode(exist.getDataNode());
        dataSource.setPublished(true);
        dataSource = dataSourceService.updateInAnyTenant(dataSource);
        result = new JsonResult<>(NO_ERROR);
        result.setResult(convertDataSourceToDTO(dataSource));
    }
    return result;
}
Also used : IUser(com.odysseusinc.arachne.portal.model.IUser) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)

Example 3 with CommonDataSourceDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonDataSourceDTO in project ArachneCentralAPI by OHDSI.

the class BaseDataSourceToCommonDataSourceDTOConverter method convert.

@Override
public DTO convert(DS dataSource) {
    if (dataSource == null) {
        return null;
    }
    DTO commonDataSourceDTO = createResultObject();
    commonDataSourceDTO.setId(dataSource.getId());
    commonDataSourceDTO.setUuid(dataSource.getUuid());
    commonDataSourceDTO.setName(dataSource.getName());
    commonDataSourceDTO.setModelType(dataSource.getModelType());
    commonDataSourceDTO.setCdmVersion(dataSource.getCdmVersion());
    commonDataSourceDTO.setOrganization(dataSource.getOrganization());
    proceedAdditionalFields(commonDataSourceDTO, dataSource);
    commonDataSourceDTO.setPublished(dataSource.getPublished());
    commonDataSourceDTO.setDbmsType(dataSource.getDbmsType());
    return commonDataSourceDTO;
}
Also used : CommonBaseDataSourceDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonBaseDataSourceDTO)

Aggregations

CommonBaseDataSourceDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonBaseDataSourceDTO)1 CommonDataSourceDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonDataSourceDTO)1 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 DataNode (com.odysseusinc.arachne.portal.model.DataNode)1 IUser (com.odysseusinc.arachne.portal.model.IUser)1 ApiOperation (io.swagger.annotations.ApiOperation)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1