MCPcopy Create free account
hub / github.com/Grashjs/cmms / create

Method create

api/src/main/java/com/grash/service/AssetService.java:78–103  ·  view source on GitHub ↗
(Asset asset, User user)

Source from the content-addressed store, hash-verified

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);

Callers 1

createAssetDowntimeMethod · 0.45

Calls 9

checkUsageBasedLimitMethod · 0.95
setAssetCustomFieldsMethod · 0.95
getAssetNumberMethod · 0.95
isEmptyMethod · 0.80
hasEntitlementMethod · 0.80
dispatchWebhookMethod · 0.80
fromPostDtoMethod · 0.65
toShowDtoMethod · 0.65
refreshMethod · 0.45

Tested by

no test coverage detected