use of com.icthh.xm.commons.exceptions.BusinessException in project xm-ms-entity by xm-online.
the class TenantService method addTenant.
public void addTenant(Tenant tenant) {
StopWatch stopWatch = StopWatch.createStarted();
log.info("START - SETUP:CreateTenant: tenantKey: {}", tenant);
if (!Constants.TENANT_XM.equals(TenantContextUtils.getRequiredTenantKeyValue(tenantContextHolder))) {
throw new BusinessException("Only 'XM' tenant allow to create new tenant");
}
try {
String tenantName = tenant.getTenantKey().toUpperCase();
tenantListRepository.addTenant(tenantName);
addEntitySpecification(tenantName);
addWebAppSpecification(tenantName);
tenantDatabaseService.createSchema(tenant);
tenantDatabaseService.createProfile(tenantName);
tenantElasticService.create(tenant);
log.info("STOP - SETUP:CreateTenant: tenantKey: {}, result: OK, time = {} ms", tenant, stopWatch.getTime());
} catch (Exception e) {
log.info("STOP - SETUP:CreateTenant: tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenant, e.getMessage(), stopWatch.getTime());
throw e;
}
}
use of com.icthh.xm.commons.exceptions.BusinessException in project xm-ms-entity by xm-online.
the class StorageRepository method store.
private String store(InputStream stream, Integer size, String contentType, String name) {
try {
if (size != null && contentType != null && "image".equals(contentType.substring(0, 5))) {
stream = ImageResizeUtil.resize(stream, size);
}
String filename = UUID.randomUUID().toString() + "." + FilenameUtils.getExtension(name);
amazonS3Template.save(filename, stream);
IOUtils.closeQuietly(stream);
String prefix = String.format(applicationProperties.getAmazon().getAws().getTemplate(), applicationProperties.getAmazon().getS3().getBucket());
return prefix + filename;
} catch (IOException e) {
log.error("Error storing file", e);
throw new BusinessException("Error storing file");
}
}
use of com.icthh.xm.commons.exceptions.BusinessException in project xm-ms-entity by xm-online.
the class XmEntityServiceImpl method exportEntities.
@LogicExtensionPoint("Export")
@Override
public byte[] exportEntities(String fileFormat, String typeKey) {
Set<String> typeKeys = xmEntitySpecService.findNonAbstractTypesByPrefix(typeKey).stream().map(TypeSpec::getKey).collect(Collectors.toSet());
List<XmEntity> xmEntities = xmEntityRepository.findAllByTypeKeyIn(new PageRequest(0, Integer.MAX_VALUE), typeKeys).getContent();
ModelMapper modelMapper = new ModelMapper();
List<SimpleExportXmEntityDto> simpleEntities = xmEntities.stream().map(entity -> modelMapper.map(entity, SimpleExportXmEntityDto.class)).collect(Collectors.toList());
switch(FileFormatEnum.valueOf(fileFormat.toUpperCase())) {
case CSV:
return EntityToCsvConverterUtils.toCsv(simpleEntities, SimpleExportXmEntityDto.class);
case XLSX:
return EntityToExcelConverterUtils.toExcel(simpleEntities, typeKey);
default:
throw new BusinessException(ErrorConstants.ERR_VALIDATION, String.format("Converter doesn't support '%s' file format", fileFormat));
}
}
use of com.icthh.xm.commons.exceptions.BusinessException in project xm-ms-entity by xm-online.
the class XmEntityServiceImpl method deleteLinkTarget.
@Override
public void deleteLinkTarget(IdOrKey idOrKey, String linkId) {
XmEntity source = toSourceXmEntity(idOrKey);
Long longLinkId = Long.parseLong(linkId);
Link foundLink = linkService.findOne(longLinkId);
if (foundLink == null) {
throw new IllegalArgumentException("Link not found by id " + linkId);
}
Long foundSourceId = foundLink.getSource().getId();
if (!foundSourceId.equals(source.getId())) {
throw new BusinessException("Wrong source id. Expected " + source.getId() + " found " + foundSourceId);
}
log.debug("Delete link by id " + linkId);
linkService.delete(longLinkId);
}
use of com.icthh.xm.commons.exceptions.BusinessException in project xm-ms-entity by xm-online.
the class LocationResource method createLocation.
/**
* POST /locations : Create a new location.
*
* @param location the location to create
* @return the ResponseEntity with status 201 (Created) and with body the new location, or with status 400 (Bad Request) if the location has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/locations")
@Timed
@PreAuthorize("hasPermission({'location': #location}, 'LOCATION.CREATE')")
public ResponseEntity<Location> createLocation(@Valid @RequestBody Location location) throws URISyntaxException {
if (location.getId() != null) {
throw new BusinessException(ErrorConstants.ERR_BUSINESS_IDEXISTS, "A new location cannot already have an ID");
}
Location result = locationRepository.save(location);
locationSearchRepository.save(result);
return ResponseEntity.created(new URI("/api/locations/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Aggregations