Skip to content

Commit

Permalink
fix usage of event
Browse files Browse the repository at this point in the history
  • Loading branch information
hilpitome committed Jan 24, 2024
1 parent 43ca92d commit bfa0aba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<artifactId>opensrp-server-core</artifactId>
<packaging>jar</packaging>
<version>2.14.9-DEV5-SNAPSHOT</version>
<version>2.14.9-ALPHA-SNAPSHOT</version>
<name>opensrp-server-core</name>
<description>OpenSRP Server Core module</description>
<url>https://github.com/OpenSRP/opensrp-server-core</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.apache.commons.lang3.tuple.Pair;
import org.opensrp.domain.LocationDetail;
import org.opensrp.domain.StructureCount;
import org.opensrp.repository.postgres.StructureListener;
import org.smartregister.domain.PhysicalLocation;
import org.opensrp.domain.StructureDetails;
import org.opensrp.search.LocationSearchBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.opensrp.domain.postgres.StructureMetadata;
import org.opensrp.domain.postgres.StructureMetadataExample;
import org.opensrp.repository.LocationRepository;
import org.opensrp.repository.StructureCreateOrUpdateEvent;
import org.opensrp.repository.postgres.mapper.custom.CustomLocationMapper;
import org.opensrp.repository.postgres.mapper.custom.CustomLocationMetadataMapper;
import org.opensrp.repository.postgres.mapper.custom.CustomStructureMapper;
Expand Down Expand Up @@ -164,8 +165,8 @@ private void addStructure(PhysicalLocation entity) {
StructureMetadata structureMetadata = createStructureMetadata(entity, pgStructure.getId());

structureMetadataMapper.insertSelective(structureMetadata);

applicationEventPublisher.publishEvent(pgStructure);
StructureCreateOrUpdateEvent structureEvent = new StructureCreateOrUpdateEvent(pgStructure);
applicationEventPublisher.publishEvent(structureEvent);
}

@Override
Expand Down Expand Up @@ -234,7 +235,8 @@ private void updateStructure(PhysicalLocation entity, Long id) {
structureMetadata.setId(metadata.getId());
structureMetadata.setDateCreated(metadata.getDateCreated());
structureMetadataMapper.updateByPrimaryKey(structureMetadata);
applicationEventPublisher.publishEvent(pgStructure);
StructureCreateOrUpdateEvent structureEvent = new StructureCreateOrUpdateEvent(pgStructure);
applicationEventPublisher.publishEvent(structureEvent);
}

@Override
Expand Down
23 changes: 8 additions & 15 deletions src/main/java/org/opensrp/service/PhysicalLocationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,20 @@
import org.opensrp.domain.StructureDetails;
import org.opensrp.domain.postgres.Structure;
import org.opensrp.repository.LocationRepository;
import org.opensrp.repository.StructureCreateOrUpdateEvent;
import org.opensrp.search.LocationSearchBean;
import org.smartregister.domain.LocationProperty;
import org.smartregister.domain.PhysicalLocation;
import org.smartregister.domain.PlanDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

@Service
public class PhysicalLocationService implements ApplicationListener<StructureCreateOrUpdateEvent> {
public class PhysicalLocationService {

@Autowired
PlanService planService;
Expand Down Expand Up @@ -605,32 +603,27 @@ public void regenerateTasksForOperationalArea(Structure structure){
*/
assert structure != null;
PhysicalLocation servicePoint = (PhysicalLocation) structure.getJson();
logger.info("Fetching parent location for service point "+servicePoint.getProperties().getUid());
logger.info("Fetching parent location for service point "+servicePoint.getProperties().getParentId());
String currentLevelLocationId = servicePoint.getProperties().getParentId();
// get username from service point

String username = servicePoint.getProperties().getUsername();
PhysicalLocation operationalArea = null;
for (int i = 0; i <3 ; i++) {
operationalArea = getLocation(currentLevelLocationId, false, false);
logger.info("Current operational area "+operationalArea.getProperties().getName() +" id "+operationalArea.getId());
currentLevelLocationId = operationalArea.getProperties().getParentId();
logger.info("parentId "+currentLevelLocationId);

}


if(operationalArea == null) return;
String operationalAreaId = operationalArea.getProperties().getUid();
logger.info("Generating tasks for operationalArea "+operationalArea.getProperties().getName() +"with id "+operationalAreaId);
logger.info("Generating tasks for operationalArea "+operationalArea.getProperties().getName() +"with id "+operationalArea.getId());
List<PlanDefinition> plans = planService.getPlanRepository().getPlansByServerVersionAndOperationalAreasAndStatus(0L,
Collections.singletonList(operationalAreaId), false, PlanDefinition.PlanStatus.ACTIVE);
Collections.singletonList(operationalArea.getId()), false, PlanDefinition.PlanStatus.ACTIVE);
for (PlanDefinition plan :
plans) {
logger.info("Processing tasks for planID "+plan.getIdentifier());
taskGenerator.processPlanEvaluation(plan, null,username);
}
}
@Override
public void onApplicationEvent(StructureCreateOrUpdateEvent structureCreateOrUpdateEvent) {
Structure structure = (Structure) structureCreateOrUpdateEvent.getSource();
logger.info("updating structure qw "+structure.getJson());
regenerateTasksForOperationalArea(structure);
}
}
1 change: 0 additions & 1 deletion src/main/java/org/opensrp/service/StockService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.smartregister.domain.Inventory;
import org.smartregister.domain.ProductCatalogue;
import org.smartregister.domain.PhysicalLocation;
import org.smartregister.domain.PlanDefinition;
import org.smartregister.domain.Stock;
import org.opensrp.dto.CsvBulkImportDataSummary;
import org.opensrp.dto.FailedRecordSummary;
Expand Down

0 comments on commit bfa0aba

Please sign in to comment.