From 10722d4a4abb2e6afe2af771144e64329bf01ca7 Mon Sep 17 00:00:00 2001 From: ADAM M SANADI Date: Wed, 4 Dec 2024 18:39:05 +0530 Subject: [PATCH 01/11] =?UTF-8?q?avniproject/avni-webapp#1113=20|=20stoppe?= =?UTF-8?q?d=20showing=20concept=20in=20the=20=E2=80=98Answer=20to?= =?UTF-8?q?=E2=80=99=20section=20where=20answer-concept=20mapping=20is=20v?= =?UTF-8?q?oided.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/avni/server/service/ConceptService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/avni-server-api/src/main/java/org/avni/server/service/ConceptService.java b/avni-server-api/src/main/java/org/avni/server/service/ConceptService.java index 1bdda5481..d7a6e9732 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/ConceptService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/ConceptService.java @@ -339,6 +339,7 @@ public void addDependentConcepts(ConceptUsageContract conceptUsageContract, Conc conceptContract.setName(concept.getName()); conceptContract.setId(concept.getId()); conceptContract.setUuid(concept.getUuid()); + conceptContract.setVoided(ca.isVoided()); conceptUsageContract.addConcepts(conceptContract); addDependentFormDetails(conceptUsageContract, concept); }); From ff5a96897ba486b677ef763525b8e79d0316f0b1 Mon Sep 17 00:00:00 2001 From: Joy A Date: Thu, 5 Dec 2024 15:49:10 +0530 Subject: [PATCH 02/11] avniproject/avni-client#1538 | Generate and sync identifier assignments based on device_id --- .../dao/IdentifierAssignmentRepository.java | 8 +++--- .../server/domain/IdentifierAssignment.java | 13 ++++++++- .../identifier/IdentifierGenerator.java | 2 +- ...fixedUserPoolBasedIdentifierGenerator.java | 14 ++++++---- .../UserBasedIdentifierGenerator.java | 8 ++++-- .../UserPoolBasedIdentifierGenerator.java | 8 ++++-- .../server/service/DeviceAwareService.java | 10 +++++++ .../service/IdentifierAssignmentService.java | 23 ++++++++------- .../web/IdentifierAssignmentController.java | 10 ++++--- .../org/avni/server/web/SyncController.java | 28 +++++++++++++------ .../V1_347__IdentifierAssignmentDeviceId.sql | 1 + .../dao/SubjectMigrationIntegrationTest.java | 2 +- .../UserBasedIdentifierGeneratorTest.java | 11 +++----- .../UserPoolBasedIdentifierGeneratorTest.java | 4 +-- .../server/service/sync/TestSyncService.java | 2 +- 15 files changed, 91 insertions(+), 53 deletions(-) create mode 100644 avni-server-api/src/main/java/org/avni/server/service/DeviceAwareService.java create mode 100644 avni-server-api/src/main/resources/db/migration/V1_347__IdentifierAssignmentDeviceId.sql diff --git a/avni-server-api/src/main/java/org/avni/server/dao/IdentifierAssignmentRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/IdentifierAssignmentRepository.java index 624876450..a225fcc5b 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/IdentifierAssignmentRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/IdentifierAssignmentRepository.java @@ -14,11 +14,11 @@ @Repository @RepositoryRestResource(collectionResourceRel = "identifierAssignment", path = "identifierAssignment") public interface IdentifierAssignmentRepository extends TransactionalDataRepository, FindByLastModifiedDateTime { - Page findByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullOrderByAssignmentOrderAsc(User currentUser, Date lastModifiedDateTime, Pageable pageable); + Page findByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEqualsOrderByAssignmentOrderAsc(User currentUser, Date lastModifiedDateTime, String deviceId, Pageable pageable); - Slice findSliceByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullOrderByAssignmentOrderAsc(User currentUser, Date lastModifiedDateTime, Pageable pageable); + Slice findSliceByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEqualsOrderByAssignmentOrderAsc(User currentUser, Date lastModifiedDateTime, String deviceId, Pageable pageable); - Integer countIdentifierAssignmentByIdentifierSourceEqualsAndAndAssignedToEqualsAndIndividualIsNullAndProgramEnrolmentIsNullAndUsedIsFalse(IdentifierSource identifierSource, User assignedTo); + Integer countIdentifierAssignmentByIdentifierSourceEqualsAndAssignedToEqualsAndIndividualIsNullAndProgramEnrolmentIsNullAndUsedIsFalseAndDeviceIdEquals(IdentifierSource identifierSource, User assignedTo, String deviceId); - boolean existsByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNull(User currentUser, Date lastModifiedDateTime); + boolean existsByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEquals(User currentUser, Date lastModifiedDateTime, String deviceId); } diff --git a/avni-server-api/src/main/java/org/avni/server/domain/IdentifierAssignment.java b/avni-server-api/src/main/java/org/avni/server/domain/IdentifierAssignment.java index 2fb91f24f..b48a638c5 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/IdentifierAssignment.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/IdentifierAssignment.java @@ -37,16 +37,19 @@ public class IdentifierAssignment extends OrganisationAwareEntity { @NotNull private boolean used; + private String deviceId; + public IdentifierAssignment() { super(); } - public IdentifierAssignment(IdentifierSource identifierSource, String identifier, Long assignmentOrder, User assignedTo) { + public IdentifierAssignment(IdentifierSource identifierSource, String identifier, Long assignmentOrder, User assignedTo, String deviceId) { this(); this.identifierSource = identifierSource; this.identifier = identifier; this.assignmentOrder = assignmentOrder; this.assignedTo = assignedTo; + this.deviceId = deviceId; } public IdentifierSource getIdentifierSource() { @@ -104,4 +107,12 @@ public boolean isUsed() { public void setUsed(boolean used) { this.used = used; } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } } diff --git a/avni-server-api/src/main/java/org/avni/server/identifier/IdentifierGenerator.java b/avni-server-api/src/main/java/org/avni/server/identifier/IdentifierGenerator.java index 534dd402f..4c2f24107 100644 --- a/avni-server-api/src/main/java/org/avni/server/identifier/IdentifierGenerator.java +++ b/avni-server-api/src/main/java/org/avni/server/identifier/IdentifierGenerator.java @@ -5,6 +5,6 @@ import org.avni.server.domain.User; public interface IdentifierGenerator { - void generateIdentifiers(IdentifierSource identifierSource, User user); + void generateIdentifiers(IdentifierSource identifierSource, User user, String deviceId); IdentifierAssignment generateSingleIdentifier(IdentifierSource identifierSource, User user); } diff --git a/avni-server-api/src/main/java/org/avni/server/identifier/PrefixedUserPoolBasedIdentifierGenerator.java b/avni-server-api/src/main/java/org/avni/server/identifier/PrefixedUserPoolBasedIdentifierGenerator.java index 0a5c6c2be..1eb005466 100644 --- a/avni-server-api/src/main/java/org/avni/server/identifier/PrefixedUserPoolBasedIdentifierGenerator.java +++ b/avni-server-api/src/main/java/org/avni/server/identifier/PrefixedUserPoolBasedIdentifierGenerator.java @@ -41,7 +41,7 @@ public PrefixedUserPoolBasedIdentifierGenerator(IdentifierAssignmentRepository i } @Transactional - public void generateIdentifiers(IdentifierSource identifierSource, User user, String prefix) { + public void generateIdentifiers(IdentifierSource identifierSource, User user, String prefix, String deviceId) { List identifierUserAssignments = identifierUserAssignmentRepository.getAllNonExhaustedUserAssignments(user, identifierSource); Long batchGenerationSize = identifierSource.getBatchGenerationSize(); NextIdentifierUserAssignment nextIdentifierUserAssignment = new NextIdentifierUserAssignment(identifierUserAssignments, batchGenerationSize); @@ -49,7 +49,7 @@ public void generateIdentifiers(IdentifierSource identifierSource, User user, St while(nextIdentifierUserAssignment.hasNext()) { IdentifierUserAssignment identifierUserAssignment = nextIdentifierUserAssignment.next(); - generatedIdentifiers.add(assignNextIdentifier(identifierUserAssignment, prefix)); + generatedIdentifiers.add(assignNextIdentifier(identifierUserAssignment, prefix, deviceId)); } identifierUserAssignmentRepository.saveAll(identifierUserAssignments); @@ -57,14 +57,16 @@ public void generateIdentifiers(IdentifierSource identifierSource, User user, St } @Transactional - public IdentifierAssignment generateSingleIdentifier(IdentifierSource identifierSource, User user, String prefix) { + public IdentifierAssignment generateSingleIdentifier(IdentifierSource identifierSource, User user, String prefix, String deviceId) { List identifierUserAssignments = identifierUserAssignmentRepository.getAllNonExhaustedUserAssignments(user, identifierSource); NextIdentifierUserAssignment nextIdentifierUserAssignment = new NextIdentifierUserAssignment(identifierUserAssignments, 1L); List generatedIdentifiers = new ArrayList<>(); while(nextIdentifierUserAssignment.hasNext()) { IdentifierUserAssignment identifierUserAssignment = nextIdentifierUserAssignment.next(); - generatedIdentifiers.add(assignNextIdentifier(identifierUserAssignment, prefix)); + IdentifierAssignment identifierAssignment = assignNextIdentifier(identifierUserAssignment, prefix, deviceId); + identifierAssignment.setUsed(true); + generatedIdentifiers.add(identifierAssignment); } identifierUserAssignmentRepository.saveAll(identifierUserAssignments); @@ -72,7 +74,7 @@ public IdentifierAssignment generateSingleIdentifier(IdentifierSource identifier return generatedIdentifiers.stream().findFirst().orElse(null); } - private IdentifierAssignment assignNextIdentifier(IdentifierUserAssignment identifierUserAssignment, String prefix) { + private IdentifierAssignment assignNextIdentifier(IdentifierUserAssignment identifierUserAssignment, String prefix, String deviceId) { String lastAssignedIdentifier = identifierUserAssignment.getLastAssignedIdentifier(); IdentifierSource identifierSource = identifierUserAssignment.getIdentifierSource(); long newIdentifierOrder; String newIdentifierStr, newIdentifierStrWithPrefix; @@ -92,7 +94,7 @@ private IdentifierAssignment assignNextIdentifier(IdentifierUserAssignment ident identifierUserAssignment.setLastAssignedIdentifier(newIdentifierStrWithPrefix); - IdentifierAssignment identifierAssignment = new IdentifierAssignment(identifierSource, newIdentifierStrWithPrefix, newIdentifierOrder, identifierUserAssignment.getAssignedTo()); + IdentifierAssignment identifierAssignment = new IdentifierAssignment(identifierSource, newIdentifierStrWithPrefix, newIdentifierOrder, identifierUserAssignment.getAssignedTo(), deviceId); identifierAssignment.assignUUID(); return identifierAssignment; } diff --git a/avni-server-api/src/main/java/org/avni/server/identifier/UserBasedIdentifierGenerator.java b/avni-server-api/src/main/java/org/avni/server/identifier/UserBasedIdentifierGenerator.java index 658a8f480..1aee1149b 100644 --- a/avni-server-api/src/main/java/org/avni/server/identifier/UserBasedIdentifierGenerator.java +++ b/avni-server-api/src/main/java/org/avni/server/identifier/UserBasedIdentifierGenerator.java @@ -5,6 +5,8 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; +import static org.avni.server.service.DeviceAwareService.WEB_DEVICE_ID; + @Service @Qualifier("userBasedIdentifierGenerator") public class UserBasedIdentifierGenerator implements IdentifierGenerator { @@ -18,15 +20,15 @@ public UserBasedIdentifierGenerator(PrefixedUserPoolBasedIdentifierGenerator pre } @Override - public void generateIdentifiers(IdentifierSource identifierSource, User user) { + public void generateIdentifiers(IdentifierSource identifierSource, User user, String deviceId) { String idPrefix = getIdPrefix(user); - prefixedUserPoolBasedIdentifierGenerator.generateIdentifiers(identifierSource, user, idPrefix); + prefixedUserPoolBasedIdentifierGenerator.generateIdentifiers(identifierSource, user, idPrefix, deviceId); } @Override public IdentifierAssignment generateSingleIdentifier(IdentifierSource identifierSource, User user) { String idPrefix = getIdPrefix(user); - IdentifierAssignment identifierAssignment = prefixedUserPoolBasedIdentifierGenerator.generateSingleIdentifier(identifierSource, user, idPrefix); + IdentifierAssignment identifierAssignment = prefixedUserPoolBasedIdentifierGenerator.generateSingleIdentifier(identifierSource, user, idPrefix, WEB_DEVICE_ID); return identifierAssignment; } diff --git a/avni-server-api/src/main/java/org/avni/server/identifier/UserPoolBasedIdentifierGenerator.java b/avni-server-api/src/main/java/org/avni/server/identifier/UserPoolBasedIdentifierGenerator.java index 31dca3990..9ad99093d 100644 --- a/avni-server-api/src/main/java/org/avni/server/identifier/UserPoolBasedIdentifierGenerator.java +++ b/avni-server-api/src/main/java/org/avni/server/identifier/UserPoolBasedIdentifierGenerator.java @@ -9,6 +9,8 @@ import javax.transaction.Transactional; +import static org.avni.server.service.DeviceAwareService.WEB_DEVICE_ID; + @Service @Qualifier("userPoolBasedIdentifierGenerator") @@ -23,14 +25,14 @@ public UserPoolBasedIdentifierGenerator(PrefixedUserPoolBasedIdentifierGenerator @Override @Transactional - public void generateIdentifiers(IdentifierSource identifierSource, User user) { + public void generateIdentifiers(IdentifierSource identifierSource, User user, String deviceId) { String prefix = identifierSource.getPrefix(); - prefixedUserPoolBasedIdentifierGenerator.generateIdentifiers(identifierSource, user, prefix); + prefixedUserPoolBasedIdentifierGenerator.generateIdentifiers(identifierSource, user, prefix, deviceId); } @Override public IdentifierAssignment generateSingleIdentifier(IdentifierSource identifierSource, User user) { String prefix = identifierSource.getPrefix(); - return prefixedUserPoolBasedIdentifierGenerator.generateSingleIdentifier(identifierSource, user, prefix); + return prefixedUserPoolBasedIdentifierGenerator.generateSingleIdentifier(identifierSource, user, prefix, WEB_DEVICE_ID); } } diff --git a/avni-server-api/src/main/java/org/avni/server/service/DeviceAwareService.java b/avni-server-api/src/main/java/org/avni/server/service/DeviceAwareService.java new file mode 100644 index 000000000..207c177a7 --- /dev/null +++ b/avni-server-api/src/main/java/org/avni/server/service/DeviceAwareService.java @@ -0,0 +1,10 @@ +package org.avni.server.service; + +import org.joda.time.DateTime; + +public interface DeviceAwareService { + String WEB_DEVICE_ID = "web"; + + boolean isSyncRequiredForDevice(DateTime lastModifiedDateTime, String deviceId); + +} diff --git a/avni-server-api/src/main/java/org/avni/server/service/IdentifierAssignmentService.java b/avni-server-api/src/main/java/org/avni/server/service/IdentifierAssignmentService.java index 7ff80abfd..584ff7661 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/IdentifierAssignmentService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/IdentifierAssignmentService.java @@ -21,7 +21,7 @@ import java.util.stream.Collectors; @Service -public class IdentifierAssignmentService implements NonScopeAwareService { +public class IdentifierAssignmentService implements DeviceAwareService { private IdentifierSourceRepository identifierSourceRepository; @@ -38,18 +38,18 @@ public IdentifierAssignmentService(IdentifierSourceRepository identifierSourceRe @Transactional - public void generateIdentifiersIfNecessary(User user) { + public void generateIdentifiersIfNecessary(User user, String deviceId) { List allAuthorisedIdentifierSources = identifierSourceRepository.getAllAuthorisedIdentifierSources(user.getCatchment()); for (IdentifierSource identifierSource : allAuthorisedIdentifierSources) { - generateIdentifiersIfNecessary(user, identifierSource); + generateIdentifiersIfNecessary(user, identifierSource, deviceId); } } @Transactional - public void generateIdentifiersIfNecessary(User user, IdentifierSource identifierSource) { - if (shouldGenerateIdentifiers(user, identifierSource)) { + public void generateIdentifiersIfNecessary(User user, IdentifierSource identifierSource, String deviceId) { + if (shouldGenerateIdentifiers(user, identifierSource, deviceId)) { IdentifierGenerator identifierGenerator = context.getBean(identifierSource.getType().name(), IdentifierGenerator.class); - identifierGenerator.generateIdentifiers(identifierSource, user); + identifierGenerator.generateIdentifiers(identifierSource, user, deviceId); } } @@ -65,15 +65,14 @@ public List generateIdentifiersForAForm(Form form, User us }).collect(Collectors.toList()); } - private boolean shouldGenerateIdentifiers(User user, IdentifierSource identifierSource) { - Integer spareIdentifierAssignments = identifierAssignmentRepository.countIdentifierAssignmentByIdentifierSourceEqualsAndAndAssignedToEqualsAndIndividualIsNullAndProgramEnrolmentIsNullAndUsedIsFalse(identifierSource, user); + private boolean shouldGenerateIdentifiers(User user, IdentifierSource identifierSource, String deviceId) { + Integer spareIdentifierAssignments = identifierAssignmentRepository.countIdentifierAssignmentByIdentifierSourceEqualsAndAssignedToEqualsAndIndividualIsNullAndProgramEnrolmentIsNullAndUsedIsFalseAndDeviceIdEquals(identifierSource, user, deviceId); return spareIdentifierAssignments < identifierSource.getMinimumBalance(); } @Override - public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { + public boolean isSyncRequiredForDevice(DateTime lastModifiedDateTime, String deviceId) { User user = UserContextHolder.getUserContext().getUser(); - this.generateIdentifiersIfNecessary(user); - return identifierAssignmentRepository.existsByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNull(user, CHSEntity.toDate(lastModifiedDateTime)); - } + this.generateIdentifiersIfNecessary(user, deviceId); + return identifierAssignmentRepository.existsByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEquals(user, CHSEntity.toDate(lastModifiedDateTime), deviceId); } } diff --git a/avni-server-api/src/main/java/org/avni/server/web/IdentifierAssignmentController.java b/avni-server-api/src/main/java/org/avni/server/web/IdentifierAssignmentController.java index 191296e97..1602523a0 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/IdentifierAssignmentController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/IdentifierAssignmentController.java @@ -60,11 +60,12 @@ public IdentifierAssignmentController(IdentifierAssignmentRepository identifierA @Transactional public PagedResources> get( @RequestParam("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, + @RequestParam(value = "deviceId", required = false) String deviceId, Pageable pageable) { User currentUser = userService.getCurrentUser(); - identifierAssignmentService.generateIdentifiersIfNecessary(currentUser); + identifierAssignmentService.generateIdentifiersIfNecessary(currentUser, deviceId); - return wrap(identifierAssignmentRepository.findByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullOrderByAssignmentOrderAsc(currentUser, CHSEntity.toDate(lastModifiedDateTime), pageable)); + return wrap(identifierAssignmentRepository.findByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEqualsOrderByAssignmentOrderAsc(currentUser, CHSEntity.toDate(lastModifiedDateTime), deviceId, pageable)); } @RequestMapping(value = "/identifierAssignment/v2", method = RequestMethod.GET) @@ -72,11 +73,12 @@ public PagedResources> get( @Transactional public SlicedResources> getAsSlice( @RequestParam("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, + @RequestParam(value = "deviceId", required = false) String deviceId, Pageable pageable) { User currentUser = userService.getCurrentUser(); - identifierAssignmentService.generateIdentifiersIfNecessary(currentUser); + identifierAssignmentService.generateIdentifiersIfNecessary(currentUser, deviceId); - return wrap(identifierAssignmentRepository.findSliceByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullOrderByAssignmentOrderAsc(currentUser, CHSEntity.toDate(lastModifiedDateTime), pageable)); + return wrap(identifierAssignmentRepository.findSliceByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEqualsOrderByAssignmentOrderAsc(currentUser, CHSEntity.toDate(lastModifiedDateTime), deviceId, pageable)); } @RequestMapping(value = "/identifierAssignments", method = RequestMethod.POST) diff --git a/avni-server-api/src/main/java/org/avni/server/web/SyncController.java b/avni-server-api/src/main/java/org/avni/server/web/SyncController.java index 52535bded..b2df02101 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/SyncController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/SyncController.java @@ -38,6 +38,7 @@ public class SyncController { private final Environment environment; private final Map scopeAwareServiceMap = new HashMap<>(); private final Map nonScopeAwareServiceMap = new HashMap<>(); + private final Map deviceAwareServiceMap = new HashMap<>(); private final IndividualService individualService; private final EncounterService encounterService; private final ProgramEnrolmentService programEnrolmentService; @@ -210,6 +211,7 @@ public SyncController(Environment environment, IndividualService individualServi public void init() { populateScopeAwareRepositoryMap(); populateEntityNameToTableMap(); + populateDeviceAwareServiceMap(); } private void populateScopeAwareRepositoryMap() { @@ -235,7 +237,6 @@ private void populateScopeAwareRepositoryMap() { } private void populateEntityNameToTableMap() { - nonScopeAwareServiceMap.put(IdentifierAssignment, identifierAssignmentService); nonScopeAwareServiceMap.put(ChecklistDetail, checklistDetailService); nonScopeAwareServiceMap.put(Rule, ruleService); nonScopeAwareServiceMap.put(RuleDependency, ruleDependencyService); @@ -286,6 +287,10 @@ private void populateEntityNameToTableMap() { nonScopeAwareServiceMap.put(UserSubjectAssignment, userSubjectAssignmentService); } + private void populateDeviceAwareServiceMap() { + deviceAwareServiceMap.put(IdentifierAssignment, identifierAssignmentService); + } + /** * @param entitySyncStatusContracts : This would contain all entries from EntitySyncStatus table maintained on avni-client, * which get populated based on all type of entities synced previously @@ -294,14 +299,15 @@ private void populateEntityNameToTableMap() { @PreAuthorize(value = "hasAnyAuthority('user')") public ResponseEntity getSyncDetailsWithScopeAwareEAS(@RequestBody List entitySyncStatusContracts, @RequestParam(value = "isStockApp", required = false) boolean isStockApp, - @RequestParam(value = "includeUserSubjectType", required = false, defaultValue = "false") boolean includeUserSubjectType) { + @RequestParam(value = "includeUserSubjectType", required = false, defaultValue = "false") boolean includeUserSubjectType, + @RequestParam(value = "deviceId", required = false) String deviceId) { DateTime now = new DateTime(); DateTime nowMinus10Seconds = getNowMinus10Seconds(); Set allSyncableItems = syncDetailService.getAllSyncableItems(true, includeUserSubjectType); long afterSyncDetailsService = new DateTime().getMillis(); logger.info(String.format("Time taken for syncDetailsService %d", afterSyncDetailsService - now.getMillis())); try { - List changedEntities = getChangedEntities(entitySyncStatusContracts, allSyncableItems, true); + List changedEntities = getChangedEntities(entitySyncStatusContracts, allSyncableItems, true, deviceId); logger.info(String.format("Time taken for stuff %d", new DateTime().getMillis() - afterSyncDetailsService)); return ResponseEntity.ok().body(new JsonObject() .with("syncDetails", changedEntities) @@ -324,13 +330,14 @@ public ResponseEntity getSyncDetailsWithScopeAwareEAS(@RequestBody List getSyncDetails(@RequestBody List entitySyncStatusContracts, @RequestParam(value = "isStockApp", required = false) boolean isStockApp, - @RequestParam(value = "includeUserSubjectType", required = false, defaultValue = "false") boolean includeUserSubjectType) { + @RequestParam(value = "includeUserSubjectType", required = false, defaultValue = "false") boolean includeUserSubjectType, + @RequestParam(value = "deviceId", required = false) String deviceId) { DateTime now = new DateTime(); DateTime nowMinus10Seconds = getNowMinus10Seconds(); Set allSyncableItems = syncDetailService.getAllSyncableItems(false, includeUserSubjectType); long afterSyncDetailsService = new DateTime().getMillis(); logger.info(String.format("Time taken for syncDetailsService %d", afterSyncDetailsService - now.getMillis())); - List changedEntities = getChangedEntities(entitySyncStatusContracts, allSyncableItems, false); + List changedEntities = getChangedEntities(entitySyncStatusContracts, allSyncableItems, false, deviceId); logger.info(String.format("Time taken for stuff %d", new DateTime().getMillis() - afterSyncDetailsService)); return ResponseEntity.ok().body(new JsonObject() .with("syncDetails", changedEntities) @@ -339,7 +346,7 @@ public ResponseEntity getSyncDetails(@RequestBody List getChangedEntities(List clientSyncStatuses, Set serverSyncableItems, boolean scopeAwareEAS) { + private List getChangedEntities(List clientSyncStatuses, Set serverSyncableItems, boolean scopeAwareEAS, String deviceId) { serverSyncableItems.forEach(syncableItem -> { if (clientSyncStatuses.stream().noneMatch(clientSyncStatus -> clientSyncStatus.matchesEntity(syncableItem))) { clientSyncStatuses.add(EntitySyncStatusContract.createForEntityWithSubType(syncableItem.getSyncEntityName(), syncableItem.getEntityTypeUuid())); @@ -348,7 +355,7 @@ private List getChangedEntities(List filterChangedEntities(entitySyncStatusContract, scopeAwareEAS)) + .filter((entitySyncStatusContract) -> filterChangedEntities(entitySyncStatusContract, scopeAwareEAS, deviceId)) .collect(Collectors.toList()); } @@ -388,7 +395,7 @@ private void removeDisabledEntities(List entitySyncSta allSyncableItems.stream().noneMatch(entitySyncStatusContract::matchesEntity)); } - private boolean filterChangedEntities(EntitySyncStatusContract entitySyncStatusContract, boolean scopeAwareEAS) { + private boolean filterChangedEntities(EntitySyncStatusContract entitySyncStatusContract, boolean scopeAwareEAS, String deviceId) { String entityName = entitySyncStatusContract.getEntityName(); DateTime loadedSince = entitySyncStatusContract.getLoadedSince(); if (scopeAwareEAS) nonScopeAwareServiceMap.remove(EntityApprovalStatus); @@ -400,6 +407,11 @@ private boolean filterChangedEntities(EntitySyncStatusContract entitySyncStatusC SyncEntityName syncEntityName = valueOf(entityName); ScopeAwareService scopeAwareService = this.scopeAwareServiceMap.get(syncEntityName); NonScopeAwareService nonScopeAwareService = this.nonScopeAwareServiceMap.get(syncEntityName); + DeviceAwareService deviceAwareService = this.deviceAwareServiceMap.get(syncEntityName); + + if (deviceAwareService != null) { + return deviceAwareService.isSyncRequiredForDevice(loadedSince, deviceId); + } if (nonScopeAwareService != null) { return nonScopeAwareService.isNonScopeEntityChanged(loadedSince); diff --git a/avni-server-api/src/main/resources/db/migration/V1_347__IdentifierAssignmentDeviceId.sql b/avni-server-api/src/main/resources/db/migration/V1_347__IdentifierAssignmentDeviceId.sql new file mode 100644 index 000000000..ae1b1f948 --- /dev/null +++ b/avni-server-api/src/main/resources/db/migration/V1_347__IdentifierAssignmentDeviceId.sql @@ -0,0 +1 @@ +alter table identifier_assignment add column device_id varchar; \ No newline at end of file diff --git a/avni-server-api/src/test/java/org/avni/server/dao/SubjectMigrationIntegrationTest.java b/avni-server-api/src/test/java/org/avni/server/dao/SubjectMigrationIntegrationTest.java index cd4f319c4..6170d46c9 100644 --- a/avni-server-api/src/test/java/org/avni/server/dao/SubjectMigrationIntegrationTest.java +++ b/avni-server-api/src/test/java/org/avni/server/dao/SubjectMigrationIntegrationTest.java @@ -71,7 +71,7 @@ private boolean hasMigrationFor(SubjectType subjectType, DateTime lastModifiedDa private List getSyncDetails() { List contracts = SyncEntityName.getNonTransactionalEntities().stream().map(EntitySyncStatusContract::createForEntityWithoutSubType).collect(Collectors.toList()); - ResponseEntity response = syncController.getSyncDetailsWithScopeAwareEAS(contracts, false, true); + ResponseEntity response = syncController.getSyncDetailsWithScopeAwareEAS(contracts, false, true, null); return ((JsonObject) response.getBody()).getList("syncDetails"); } diff --git a/avni-server-api/src/test/java/org/avni/server/identifier/UserBasedIdentifierGeneratorTest.java b/avni-server-api/src/test/java/org/avni/server/identifier/UserBasedIdentifierGeneratorTest.java index ab66bacc5..bf1cbecdd 100644 --- a/avni-server-api/src/test/java/org/avni/server/identifier/UserBasedIdentifierGeneratorTest.java +++ b/avni-server-api/src/test/java/org/avni/server/identifier/UserBasedIdentifierGeneratorTest.java @@ -1,13 +1,10 @@ package org.avni.server.identifier; -import org.avni.server.domain.UserSettings; -import org.avni.server.identifier.IdentifierGenerator; -import org.avni.server.identifier.PrefixedUserPoolBasedIdentifierGenerator; -import org.avni.server.identifier.UserBasedIdentifierGenerator; -import org.junit.Test; import org.avni.server.domain.IdentifierSource; import org.avni.server.domain.JsonObject; import org.avni.server.domain.User; +import org.avni.server.domain.UserSettings; +import org.junit.Test; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -30,8 +27,8 @@ public void shouldGenerateIdentifiersBasedOnUserIdPrefix() { IdentifierGenerator identifierGenerator = new UserBasedIdentifierGenerator(prefixedUserPoolBasedIdentifierGenerator); - identifierGenerator.generateIdentifiers(identifierSource, user); + identifierGenerator.generateIdentifiers(identifierSource, user, null); - verify(prefixedUserPoolBasedIdentifierGenerator).generateIdentifiers(identifierSource, user, "ABC"); + verify(prefixedUserPoolBasedIdentifierGenerator).generateIdentifiers(identifierSource, user, "ABC", null); } } diff --git a/avni-server-api/src/test/java/org/avni/server/identifier/UserPoolBasedIdentifierGeneratorTest.java b/avni-server-api/src/test/java/org/avni/server/identifier/UserPoolBasedIdentifierGeneratorTest.java index 11ba1e221..c95aa5d78 100644 --- a/avni-server-api/src/test/java/org/avni/server/identifier/UserPoolBasedIdentifierGeneratorTest.java +++ b/avni-server-api/src/test/java/org/avni/server/identifier/UserPoolBasedIdentifierGeneratorTest.java @@ -27,8 +27,8 @@ public void shouldGenerateIdentifiersBasedOnPrefixOfIdentifierSource() { IdentifierGenerator identifierGenerator = new UserBasedIdentifierGenerator(prefixedUserPoolBasedIdentifierGenerator); - identifierGenerator.generateIdentifiers(identifierSource, user); + identifierGenerator.generateIdentifiers(identifierSource, user, null); - verify(prefixedUserPoolBasedIdentifierGenerator).generateIdentifiers(identifierSource, user, "ABC"); + verify(prefixedUserPoolBasedIdentifierGenerator).generateIdentifiers(identifierSource, user, "ABC", null); } } diff --git a/avni-server-api/src/test/java/org/avni/server/service/sync/TestSyncService.java b/avni-server-api/src/test/java/org/avni/server/service/sync/TestSyncService.java index 3a2558b08..0f817695d 100644 --- a/avni-server-api/src/test/java/org/avni/server/service/sync/TestSyncService.java +++ b/avni-server-api/src/test/java/org/avni/server/service/sync/TestSyncService.java @@ -32,7 +32,7 @@ public TestSyncService(SyncController syncController, IndividualController indiv public List getSyncDetails() { List contracts = SyncEntityName.getNonTransactionalEntities().stream().map(EntitySyncStatusContract::createForEntityWithoutSubType).collect(Collectors.toList()); - ResponseEntity response = syncController.getSyncDetailsWithScopeAwareEAS(contracts, false, true); + ResponseEntity response = syncController.getSyncDetailsWithScopeAwareEAS(contracts, false, true, null); return ((JsonObject) response.getBody()).getList("syncDetails"); } From c79a79f35c930903815a123c5b9ffb4a55c2453d Mon Sep 17 00:00:00 2001 From: ADAM M SANADI Date: Thu, 5 Dec 2024 17:47:00 +0530 Subject: [PATCH 03/11] avniproject/avni-webapp#1113 | Returning updated IdentifierUserAssignment ResponseEntity as it is. --- .../identifier/IdentifierUserAssignmentService.java | 4 ++-- .../server/web/IdentifierUserAssignmentWebController.java | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/avni-server-api/src/main/java/org/avni/server/service/identifier/IdentifierUserAssignmentService.java b/avni-server-api/src/main/java/org/avni/server/service/identifier/IdentifierUserAssignmentService.java index 224c43b1f..56c55b43e 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/identifier/IdentifierUserAssignmentService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/identifier/IdentifierUserAssignmentService.java @@ -37,7 +37,7 @@ public void save(IdentifierUserAssignment identifierUserAssignment) throws Ident } } - public void update(IdentifierUserAssignment existingIdentifierUserAssignment, IdentifierUserAssignment newIdentifierUserAssignment) throws IdentifierOverlappingException, ValidationException { + public IdentifierUserAssignment update(IdentifierUserAssignment existingIdentifierUserAssignment, IdentifierUserAssignment newIdentifierUserAssignment) throws IdentifierOverlappingException, ValidationException { newIdentifierUserAssignment.validate(); IdentifierSource identifierSource = newIdentifierUserAssignment.getIdentifierSource(); @@ -52,7 +52,7 @@ public void update(IdentifierUserAssignment existingIdentifierUserAssignment, Id || (overlappingWithAssignments.size() == 1 && !(overlappingWithAssignments.get(0).getId().equals(existingIdentifierUserAssignment.getId())))) throw new IdentifierOverlappingException(overlappingWithAssignments); - identifierUserAssignmentRepository.updateExistingWithNew(existingIdentifierUserAssignment, newIdentifierUserAssignment); + return identifierUserAssignmentRepository.updateExistingWithNew(existingIdentifierUserAssignment, newIdentifierUserAssignment); } } } diff --git a/avni-server-api/src/main/java/org/avni/server/web/IdentifierUserAssignmentWebController.java b/avni-server-api/src/main/java/org/avni/server/web/IdentifierUserAssignmentWebController.java index 376c43c03..0110df5c3 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/IdentifierUserAssignmentWebController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/IdentifierUserAssignmentWebController.java @@ -89,12 +89,13 @@ public ResponseEntity updateIdAssignment(@RequestBody IdentifierUserAssignmentCo IdentifierUserAssignment identifierUserAssignment = getIdentifierUserAssignment(request); identifierUserAssignment.setVoided(request.isVoided()); + IdentifierUserAssignment updatedIdentifierUserAssignment; try { - identifierUserAssignmentService.update(existingIdentifierUserAssignment, identifierUserAssignment); + updatedIdentifierUserAssignment = identifierUserAssignmentService.update(existingIdentifierUserAssignment, identifierUserAssignment); } catch (IdentifierOverlappingException | ValidationException e) { return WebResponseUtil.createBadRequestResponse(e, logger); } - return ResponseEntity.ok(IdentifierUserAssignmentContractWeb.fromIdentifierUserAssignment(identifierUserAssignment)); + return ResponseEntity.ok(IdentifierUserAssignmentContractWeb.fromIdentifierUserAssignment(updatedIdentifierUserAssignment)); } @DeleteMapping(value = "/web/identifierUserAssignment/{id}") @@ -116,8 +117,6 @@ private IdentifierUserAssignment getIdentifierUserAssignment(IdentifierUserAssig identifierUserAssignment.setIdentifierSource(request.getIdentifierSourceId() == null ? null : identifierSourceRepository.findOne(request.getIdentifierSourceId())); identifierUserAssignment.setIdentifierStart(request.getIdentifierStart()); identifierUserAssignment.setIdentifierEnd(request.getIdentifierEnd()); - identifierUserAssignment.setId(request.getId()); - identifierUserAssignment.setOrganisationId(request.getOrganisationId()); return identifierUserAssignment; } } From 98b3add58ee467cfcbf5e22ab7f976b084fcc690 Mon Sep 17 00:00:00 2001 From: vedfordev Date: Mon, 9 Dec 2024 17:32:28 +0530 Subject: [PATCH 04/11] avniproject/avni-server#826 | refactor: make org db password configurable --- .../org/avni/server/dao/ImplementationRepository.java | 4 ---- .../avni/server/service/metabase/MetabaseService.java | 6 ++++-- .../org/avni/server/web/OrganisationController.java | 7 +++++-- .../avni/server/web/OrganisationGroupController.java | 7 +++++-- .../src/main/resources/application.properties | 3 +++ .../service/builder/TestOrganisationService.java | 10 +++++++--- .../src/test/resources/application.properties | 3 +++ 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/avni-server-api/src/main/java/org/avni/server/dao/ImplementationRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/ImplementationRepository.java index de37eed6c..a58b79806 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/ImplementationRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/ImplementationRepository.java @@ -22,10 +22,6 @@ public interface ImplementationRepository extends AvniCrudRepository { + + @Value("${avni.org.password}") + private String AVNI_DEFAULT_PASSWORD; private final Logger logger; private final OrganisationGroupRepository organisationGroupRepository; private final OrganisationRepository organisationRepository; @@ -52,8 +56,7 @@ public ResponseEntity save(@RequestBody OrganisationGroupContract request) throw if (organisationGroupRepository.findByName(request.getName()) != null) { throw new ValidationException(String.format("Organisation group %s already exists", request.getName())); } - String tempPassword = "password"; - implementationRepository.createDBUser(request.getDbUser(), tempPassword); + implementationRepository.createDBUser(request.getDbUser(), AVNI_DEFAULT_PASSWORD); OrganisationGroup organisationGroup = new OrganisationGroup(); organisationGroup.setDbUser(request.getDbUser()); organisationGroup.assignUUIDIfRequired(); diff --git a/avni-server-api/src/main/resources/application.properties b/avni-server-api/src/main/resources/application.properties index dbd3bc5e7..1a73e065e 100644 --- a/avni-server-api/src/main/resources/application.properties +++ b/avni-server-api/src/main/resources/application.properties @@ -166,3 +166,6 @@ metabase.api.key=${METABASE_API_KEY:mb_uhFRMqCSre4v/hTZTsQcMnh8k2GCZFX2tGmSBdoxN # end of life avni.endpoints.endOfLife.1=${AVNI_ENDPOINT_END_OF_LIFE_1:2024-09-05} + +#default org configuration +avni.org.password=${AVNI_ORG_PASSWORD:password} \ No newline at end of file diff --git a/avni-server-api/src/test/java/org/avni/server/service/builder/TestOrganisationService.java b/avni-server-api/src/test/java/org/avni/server/service/builder/TestOrganisationService.java index f21ccf132..702ce6e11 100644 --- a/avni-server-api/src/test/java/org/avni/server/service/builder/TestOrganisationService.java +++ b/avni-server-api/src/test/java/org/avni/server/service/builder/TestOrganisationService.java @@ -1,12 +1,14 @@ package org.avni.server.service.builder; -import org.avni.server.dao.*; +import org.avni.server.dao.ImplementationRepository; +import org.avni.server.dao.OrganisationRepository; +import org.avni.server.dao.UserRepository; import org.avni.server.domain.Organisation; import org.avni.server.domain.User; -import org.avni.server.framework.security.UserContextHolder; import org.avni.server.service.OrganisationService; import org.avni.server.web.TestWebContextService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service @@ -16,6 +18,8 @@ public class TestOrganisationService { private final UserRepository userRepository; private final TestWebContextService testWebContextService; private final OrganisationService organisationService; + @Value("${avni.org.password}") + private String DEFAUT_PASSWORD; @Autowired public TestOrganisationService(ImplementationRepository implementationRepository, OrganisationRepository organisationRepository, UserRepository userRepository, TestWebContextService testWebContextService, OrganisationService organisationService) { @@ -29,7 +33,7 @@ public TestOrganisationService(ImplementationRepository implementationRepository public void createOrganisation(Organisation organisation, User adminUser) { organisationRepository.save(organisation); User orgUser = createUser(organisation, adminUser); - implementationRepository.createDBUser(organisation); + implementationRepository.createDBUser(organisation.getDbUser(),DEFAUT_PASSWORD); testWebContextService.setUser(orgUser); organisationService.setupBaseOrganisationMetadata(organisation); } diff --git a/avni-server-api/src/test/resources/application.properties b/avni-server-api/src/test/resources/application.properties index 89985b935..d559cfa41 100644 --- a/avni-server-api/src/test/resources/application.properties +++ b/avni-server-api/src/test/resources/application.properties @@ -128,3 +128,6 @@ metabase.api.key=${METABASE_API_KEY:mb_hwsYP2sFN7fvwM5LTS4d/tnIqA5SeHUxwUhm2KAI1 # end of life avni.endpoints.endOfLife.1=2024-09-09 + +#default org configuration +avni.org.password=${AVNI_DEFAULT_PASSWORD:password} \ No newline at end of file From 247ff07f4fc81b018ee53b8aade188c69120ff01 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Mon, 9 Dec 2024 18:15:13 +0530 Subject: [PATCH 05/11] #0 - concept_voided field in column metadata --- .../resources/db/migration/V1_347__AllowVoidingOfETLColumns.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 avni-server-api/src/main/resources/db/migration/V1_347__AllowVoidingOfETLColumns.sql diff --git a/avni-server-api/src/main/resources/db/migration/V1_347__AllowVoidingOfETLColumns.sql b/avni-server-api/src/main/resources/db/migration/V1_347__AllowVoidingOfETLColumns.sql new file mode 100644 index 000000000..cf7ac736c --- /dev/null +++ b/avni-server-api/src/main/resources/db/migration/V1_347__AllowVoidingOfETLColumns.sql @@ -0,0 +1 @@ +alter table column_metadata add column concept_voided boolean default false; From dba4225a979e6da3ef17e16a22670773d0994d42 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Mon, 9 Dec 2024 18:19:10 +0530 Subject: [PATCH 06/11] #0 - concept_voided field in column metadata --- ...idingOfETLColumns.sql => V1_348__AllowVoidingOfETLColumns.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename avni-server-api/src/main/resources/db/migration/{V1_347__AllowVoidingOfETLColumns.sql => V1_348__AllowVoidingOfETLColumns.sql} (100%) diff --git a/avni-server-api/src/main/resources/db/migration/V1_347__AllowVoidingOfETLColumns.sql b/avni-server-api/src/main/resources/db/migration/V1_348__AllowVoidingOfETLColumns.sql similarity index 100% rename from avni-server-api/src/main/resources/db/migration/V1_347__AllowVoidingOfETLColumns.sql rename to avni-server-api/src/main/resources/db/migration/V1_348__AllowVoidingOfETLColumns.sql From 726e19978f5eff14a75ffd401d8db27aafd3c7ae Mon Sep 17 00:00:00 2001 From: vedfordev Date: Tue, 10 Dec 2024 11:27:54 +0530 Subject: [PATCH 07/11] avniproject/avni-server#826 | refactor: environment variable name change --- avni-server-api/src/test/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avni-server-api/src/test/resources/application.properties b/avni-server-api/src/test/resources/application.properties index d559cfa41..73922b4e9 100644 --- a/avni-server-api/src/test/resources/application.properties +++ b/avni-server-api/src/test/resources/application.properties @@ -130,4 +130,4 @@ metabase.api.key=${METABASE_API_KEY:mb_hwsYP2sFN7fvwM5LTS4d/tnIqA5SeHUxwUhm2KAI1 avni.endpoints.endOfLife.1=2024-09-09 #default org configuration -avni.org.password=${AVNI_DEFAULT_PASSWORD:password} \ No newline at end of file +avni.org.password=${AVNI_ORG_PASSWORD:password} \ No newline at end of file From 13058dac58dd2664e8cd9c3e47428c0cbba8c81f Mon Sep 17 00:00:00 2001 From: himeshr Date: Tue, 10 Dec 2024 18:41:10 +0530 Subject: [PATCH 08/11] avniproject/avni-webapp#1337 | Use OPENCHS_DATABASE_HOST instead of OPENCHS_DATABASE_SERVER --- avni-server-api/src/main/resources/application.properties | 2 +- avni-server-api/src/test/resources/application.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/avni-server-api/src/main/resources/application.properties b/avni-server-api/src/main/resources/application.properties index 1a73e065e..00bdfce5c 100644 --- a/avni-server-api/src/main/resources/application.properties +++ b/avni-server-api/src/main/resources/application.properties @@ -4,7 +4,7 @@ spring.profiles.active=${OPENCHS_MODE:dev} # Database avni.database=${OPENCHS_DATABASE:openchs} avni.database.port=${OPENCHS_DATABASE_PORT:5432} -avni.database.server=${OPENCHS_DATABASE_SERVER:localhost} +avni.database.server=${OPENCHS_DATABASE_HOST:localhost} spring.datasource.url=${OPENCHS_DATABASE_URL:jdbc:postgresql://${avni.database.server}:${avni.database.port}/${avni.database}?currentSchema=public} spring.datasource.username=${OPENCHS_DATABASE_USER:openchs} spring.datasource.password=${OPENCHS_DATABASE_PASSWORD:password} diff --git a/avni-server-api/src/test/resources/application.properties b/avni-server-api/src/test/resources/application.properties index 73922b4e9..eb7831e9e 100644 --- a/avni-server-api/src/test/resources/application.properties +++ b/avni-server-api/src/test/resources/application.properties @@ -6,7 +6,7 @@ spring.servlet.multipart.max-file-size=10028KB spring.servlet.multipart.max-request-size=10028KB avni.database=${OPENCHS_DATABASE:openchs} avni.database.port=${OPENCHS_DATABASE_PORT:5432} -avni.database.server=${OPENCHS_DATABASE_SERVER:localhost} +avni.database.server=${OPENCHS_DATABASE_HOST:localhost} spring.datasource.url=${OPENCHS_DATABASE_URL:jdbc:postgresql://${avni.database.server}:${avni.database.port}/openchs_test} spring.datasource.username=${OPENCHS_DATABASE_USER:openchs} spring.datasource.password=${OPENCHS_DATABASE_PASSWORD:password} From f2e749f32d28d9a763ba74e8fdd29ff51ec33915 Mon Sep 17 00:00:00 2001 From: himeshr Date: Wed, 11 Dec 2024 12:28:18 +0530 Subject: [PATCH 09/11] avniproject/avni-webapp#1337 | Filter table names by org_schema_name --- .../server/domain/metabase/DatasetColumn.java | 3 ++- .../service/metabase/DatabaseService.java | 27 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatasetColumn.java b/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatasetColumn.java index 48509b4c7..773587a30 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatasetColumn.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatasetColumn.java @@ -2,7 +2,8 @@ public enum DatasetColumn { NAME(1), - TYPE(2); + TYPE(2), + SCHEMA_NAME(3); private final int index; diff --git a/avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java b/avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java index 98fc49f82..f59fece5a 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java @@ -4,8 +4,9 @@ import org.avni.server.domain.metabase.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Arrays; + import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -81,10 +82,12 @@ public List getSubjectTypeNames() { for (List row : rows) { String type = row.get(DatasetColumn.TYPE.getIndex()); - if (type.equalsIgnoreCase(TableType.INDIVIDUAL.getTypeName()) || - type.equalsIgnoreCase(TableType.HOUSEHOLD.getTypeName()) || - type.equalsIgnoreCase(TableType.GROUP.getTypeName()) || - type.equalsIgnoreCase(TableType.PERSON.getTypeName())) { + String schemaName = row.get(DatasetColumn.SCHEMA_NAME.getIndex()); + if (schemaName.equalsIgnoreCase(getGlobalDatabase().getName()) && + (type.equalsIgnoreCase(TableType.INDIVIDUAL.getTypeName()) || + type.equalsIgnoreCase(TableType.HOUSEHOLD.getTypeName()) || + type.equalsIgnoreCase(TableType.GROUP.getTypeName()) || + type.equalsIgnoreCase(TableType.PERSON.getTypeName()))) { subjectTypeNames.add(row.get(DatasetColumn.NAME.getIndex())); } } @@ -98,18 +101,20 @@ public List getProgramAndEncounterNames() { DatasetResponse datasetResponse = databaseRepository.findAll(fetchedMetadataTable, getGlobalDatabase()); List> rows = datasetResponse.getData().getRows(); - List programNames = new ArrayList<>(); + List programAndEncounterNames = new ArrayList<>(); for (List row : rows) { String type = row.get(DatasetColumn.TYPE.getIndex()); - if (type.equalsIgnoreCase(TableType.PROGRAM_ENCOUNTER.getTypeName()) || - type.equalsIgnoreCase(TableType.ENCOUNTER.getTypeName()) || - type.equalsIgnoreCase(TableType.PROGRAM_ENROLMENT.getTypeName())) { - programNames.add(row.get(DatasetColumn.NAME.getIndex())); + String schemaName = row.get(DatasetColumn.SCHEMA_NAME.getIndex()); + if (schemaName.equalsIgnoreCase(getGlobalDatabase().getName()) && + (type.equalsIgnoreCase(TableType.PROGRAM_ENCOUNTER.getTypeName()) || + type.equalsIgnoreCase(TableType.ENCOUNTER.getTypeName()) || + type.equalsIgnoreCase(TableType.PROGRAM_ENROLMENT.getTypeName()))) { + programAndEncounterNames.add(row.get(DatasetColumn.NAME.getIndex())); } } - return programNames; + return programAndEncounterNames; } private void createQuestionsForEntities(List entityNames, FieldDetails addressFieldDetails, FieldDetails entityFieldDetails) { From 13c370049ce73dcebc7b5c7c8dbd2ef52467f237 Mon Sep 17 00:00:00 2001 From: himeshr Date: Wed, 11 Dec 2024 12:28:36 +0530 Subject: [PATCH 10/11] avniproject/avni-webapp#1337 | Rename server hostnames --- Makefile | 6 +++--- makefiles/prerelease.mk | 2 +- makefiles/staging.mk | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index c4501216e..14bc2d0ab 100644 --- a/Makefile +++ b/Makefile @@ -164,11 +164,11 @@ start_server_wo_gradle: # LIVE log_live: - tail -f /var/log/openchs/openchs.log + tail -f /var/log/avni_server/chs.log # /LIVE tail-local-log: - tail -f -n1000 /var/log/openchs/openchs.log + tail -f -n1000 /var/log/avni_server/chs.log debug_server_live: build_server OPENCHS_MODE=live OPENCHS_CLIENT_ID=$(STAGING_APP_CLIENT_ID) OPENCHS_USER_POOL=$(STAGING_USER_POOL_ID) java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar @@ -199,4 +199,4 @@ exec-sql: ## Usage: make exec-sql sqlfile= # remote tail-prod: - ssh avni-server-prod "tail -f /var/log/openchs/openchs.log" + ssh avni-prod "tail -f /var/log/avni_server/chs.log" diff --git a/makefiles/prerelease.mk b/makefiles/prerelease.mk index 089a0f30a..a5e7f33a1 100644 --- a/makefiles/prerelease.mk +++ b/makefiles/prerelease.mk @@ -9,7 +9,7 @@ open-cognito-prerelease: open https://ap-south-1.console.aws.amazon.com/cognito/v2/idp/user-pools/ap-south-1_vfNvMvMk9/users?region=ap-south-1 start_server_prerelease: build_server - -mkdir -p /tmp/openchs && sudo ln -s /tmp/openchs /var/log/openchs + -mkdir -p /tmp/openchs && sudo ln -s /tmp/openchs /var/log/avni_server AVNI_IDP_TYPE=cognito \ OPENCHS_CLIENT_ID=$(OPENCHS_CLIENT_ID) \ diff --git a/makefiles/staging.mk b/makefiles/staging.mk index 5cfd0b4f6..07b5b6aa3 100644 --- a/makefiles/staging.mk +++ b/makefiles/staging.mk @@ -1,12 +1,12 @@ # I have setup the environment variables in my bash_profile so that I can just run it whenever I want in live mode. You could do that too (Vivek). tunnel_staging_db: - ssh avni-server-staging -L 6015:stagingdb.openchs.org:5432 + ssh avni-staging -L 6015:stagingdb.openchs.org:5432 tunnel_staging_server_for_debug: - ssh avni-server-staging -L 5005:127.0.0.1:5005 + ssh avni-staging -L 5005:127.0.0.1:5005 start_server_staging: build_server - -mkdir -p /tmp/openchs && sudo ln -s /tmp/openchs /var/log/openchs + -mkdir -p /tmp/openchs && sudo ln -s /tmp/openchs /var/log/avni_server AVNI_IDP_TYPE=cognito \ OPENCHS_CLIENT_ID=$(OPENCHS_STAGING_APP_CLIENT_ID) \ @@ -19,7 +19,7 @@ start_server_staging: build_server java -jar avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar debug_server_staging: build_server - -mkdir -p /tmp/openchs && sudo ln -s /tmp/openchs /var/log/openchs + -mkdir -p /tmp/openchs && sudo ln -s /tmp/openchs /var/log/avni_server OPENCHS_DATABASE_URL=jdbc:postgresql://localhost:5433/openchs?currentSchema=public \ AVNI_IDP_TYPE=cognito \ OPENCHS_CLIENT_ID=$(OPENCHS_STAGING_APP_CLIENT_ID) \ @@ -31,7 +31,7 @@ debug_server_staging: build_server java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar tail-staging-log: - ssh avni-server-staging "tail -f -n1000 /var/log/openchs/openchs.log" + ssh avni-staging "tail -f -n1000 /var/log/avni_server/chs.log" open-user-media-staging: ifndef orgMedia From 856d90372b62e2de1b5921a6a3c7ec5ba6b04a17 Mon Sep 17 00:00:00 2001 From: vedfordev Date: Wed, 11 Dec 2024 17:26:33 +0530 Subject: [PATCH 11/11] avniproject/avni-server#826 | refactor: variable name change for default org password --- .../org/avni/server/service/metabase/MetabaseService.java | 4 ++-- .../main/java/org/avni/server/web/OrganisationController.java | 4 ++-- .../java/org/avni/server/web/OrganisationGroupController.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java b/avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java index 3ed1ad63d..7cbba2af9 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java @@ -15,7 +15,7 @@ public class MetabaseService { @Value("${avni.org.password}") - private String AVNI_DEFAULT_PASSWORD; + private String AVNI_DEFAULT_ORG_USER_DB_PASSWORD; public static final String DB_ENGINE = "postgres"; private final OrganisationService organisationService; private final AvniDatabase avniDatabase; @@ -48,7 +48,7 @@ public void setupMetabase() { globalDatabase = databaseRepository.getDatabaseByName(new Database(name)); if (globalDatabase == null) { - Database newDatabase = new Database(name, DB_ENGINE, new DatabaseDetails(avniDatabase, dbUser, AVNI_DEFAULT_PASSWORD)); + Database newDatabase = new Database(name, DB_ENGINE, new DatabaseDetails(avniDatabase, dbUser, AVNI_DEFAULT_ORG_USER_DB_PASSWORD)); globalDatabase = databaseRepository.save(newDatabase); } diff --git a/avni-server-api/src/main/java/org/avni/server/web/OrganisationController.java b/avni-server-api/src/main/java/org/avni/server/web/OrganisationController.java index 0b279255b..b90119b01 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/OrganisationController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/OrganisationController.java @@ -31,7 +31,7 @@ public class OrganisationController implements RestControllerResourceProcessor { @Value("${avni.org.password}") - private String AVNI_DEFAULT_PASSWORD; + private String AVNI_DEFAULT_ORG_USER_DB_PASSWORD; private final Logger logger; private final OrganisationGroupRepository organisationGroupRepository; private final OrganisationRepository organisationRepository; @@ -56,7 +56,7 @@ public ResponseEntity save(@RequestBody OrganisationGroupContract request) throw if (organisationGroupRepository.findByName(request.getName()) != null) { throw new ValidationException(String.format("Organisation group %s already exists", request.getName())); } - implementationRepository.createDBUser(request.getDbUser(), AVNI_DEFAULT_PASSWORD); + implementationRepository.createDBUser(request.getDbUser(), AVNI_DEFAULT_ORG_USER_DB_PASSWORD); OrganisationGroup organisationGroup = new OrganisationGroup(); organisationGroup.setDbUser(request.getDbUser()); organisationGroup.assignUUIDIfRequired();