+ @Override
+ @Transactional
+ // A retry is made to store the schema set if it fails because of duplicated yang resource exception that
+ // can occur in case of specific concurrent requests.
+ @Retryable(value = DuplicatedYangResourceException.class, maxAttempts = 5, backoff =
+ @Backoff(random = true, delay = 200, maxDelay = 2000, multiplier = 2))
+ public void storeSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
+ final Map<String, String> newModuleNameToContentMap,
+ final Collection<ModuleReference> moduleReferences) {
+ storeSchemaSet(dataspaceName, schemaSetName, newModuleNameToContentMap);
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var schemaSetEntity =
+ schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
+ final List<Long> listOfYangResourceIds = new ArrayList<>();
+ moduleReferences.forEach(moduleReference ->
+ listOfYangResourceIds.add(yangResourceRepository.getIdByModuleNameAndRevision(
+ moduleReference.getModuleName(), moduleReference.getRevision())));
+ yangResourceRepository.insertSchemaSetIdYangResourceId(schemaSetEntity.getId(), listOfYangResourceIds);
+ }
+
+ @Override
+ @Transactional
+ public void deleteSchemaSet(final String dataspaceName, final String schemaSetName) {
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var schemaSetEntity =
+ schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
+ schemaSetRepository.delete(schemaSetEntity);
+ }
+
+ @Override
+ @Transactional
+ public void deleteUnusedYangResourceModules() {
+ yangResourceRepository.deleteOrphans();
+ }
+
+ @Override
+ public Collection<ModuleReference> identifyNewModuleReferences(
+ final Collection<ModuleReference> moduleReferencesToCheck) {
+ return moduleReferenceRepository.identifyNewModuleReferences(moduleReferencesToCheck);
+ }
+
+ private Set<YangResourceEntity> synchronizeYangResources(
+ final Map<String, String> moduleReferenceNameToContentMap) {
+ final Map<String, YangResourceEntity> checksumToEntityMap = moduleReferenceNameToContentMap.entrySet().stream()