(Asset asset, User user)
| 76 | } |
| 77 | |
| 78 | @Transactional |
| 79 | public Asset create(Asset asset, User user) { |
| 80 | checkUsageBasedLimit(user.getCompany()); |
| 81 | Company company = user.getCompany(); |
| 82 | if (asset instanceof AssetPostDTO assetPostDTO) { |
| 83 | asset = assetMapper.fromPostDto(assetPostDTO); |
| 84 | if (assetPostDTO.getCustomFields() != null && !assetPostDTO.getCustomFields().isEmpty()) { |
| 85 | setAssetCustomFields(asset, assetPostDTO.getCustomFields(), company); |
| 86 | } |
| 87 | } |
| 88 | if (asset.getParentAsset() != null && !licenseService.hasEntitlement(LicenseEntitlement.ASSET_HIERARCHY)) |
| 89 | throw new CustomException("You need a license to add a child asset to another asset.", |
| 90 | HttpStatus.FORBIDDEN); |
| 91 | asset.setCustomId(getAssetNumber(company)); |
| 92 | if ((asset.getBarCode() == null || asset.getBarCode().isBlank()) && Boolean.TRUE.equals(user.getCompany().getCompanySettings().getGeneralPreferences().getAutoGenerateAssetBarcode())) { |
| 93 | asset.setBarCode(UUID.randomUUID().toString()); |
| 94 | } |
| 95 | Asset savedAsset = assetRepository.saveAndFlush(asset); |
| 96 | em.refresh(savedAsset); |
| 97 | Map<String, Object> webhookPayload = new HashMap<>(); |
| 98 | webhookPayload.put("assetId", savedAsset.getId()); |
| 99 | Object serializedAsset = assetMapper.toShowDto(savedAsset, this); |
| 100 | webhookDispatchService.dispatchWebhook(company, WebhookEvent.NEW_ASSET, webhookPayload, |
| 101 | "newAsset", serializedAsset, null, null, null, null, null); |
| 102 | return savedAsset; |
| 103 | } |
| 104 | |
| 105 | private String getAssetNumber(Company company) { |
| 106 | Long nextSequence = customSequenceService.getNextAssetSequence(company); |
no test coverage detected