Skip to content

Commit

Permalink
AMP-30574
Browse files Browse the repository at this point in the history
Map primary and secondary sectors
  • Loading branch information
brianbrix committed Jun 14, 2024
1 parent 4a2bd1b commit e4d6ea0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public void onUpdate(List<AmpSector> data) {
secondarySectorsTable.updateBasedOnData(data);
target.add(secondarySectorsTable.getSearchSectors());
}
// if (this.primarySectorsTable.getSearchSectors().getModelParams().get(AmpSectorSearchModel.PARAM.ACTION)=="add" || this.secondarySectorsTable.getSearchSectors().getModelParams().get(AmpSectorSearchModel.PARAM.ACTION)=="add") {
// populateSecondarySectorsFor1Choice( target, secondaryConf);
// }
if (this.primarySectorsTable.getSearchSectors().getModelParams().get(AmpSectorSearchModel.PARAM.ACTION)=="add" || this.secondarySectorsTable.getSearchSectors().getModelParams().get(AmpSectorSearchModel.PARAM.ACTION)=="add") {
populateSecondarySectorsFor1Choice( target, secondaryConf);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public void setDeleteListener(ISectorTableDeleteListener listener) {
}

private AmpAutocompleteFieldPanel<AmpSector> searchSectors;
private AmpClassificationConfiguration sectorClassification;
public AmpAutocompleteFieldPanel<AmpSector> getSearchSectors() { return this.searchSectors; }
public AmpClassificationConfiguration getClassfication() { return this.sectorClassification; }

private IModel<Set<AmpActivitySector>> setModel;
public IModel<Set<AmpActivitySector>> getSetModel() { return this.setModel; }
Expand Down Expand Up @@ -102,10 +100,6 @@ public void triggerUpdateEvent(Set<AmpActivitySector> selectedSectors,
}
updateListener.onUpdate(sectorsByClassification);
}
List<AmpSector> newChoices = (List<AmpSector>)searchSectors.getModelParams().get(AmpSectorSearchModel.PARAM.NEW_CHOICES);
extracted(newChoices);


}

/**
Expand Down Expand Up @@ -202,7 +196,6 @@ public AmpSectorsFormTableFeature(String id, String fmName,
throws Exception {
super(id, am, fmName, false, true);
setModel = new PropertyModel<Set<AmpActivitySector>>(am, "sectors");
this.sectorClassification = sectorClassification;
if (setModel.getObject() == null) setModel.setObject(new HashSet<AmpActivitySector>());
if (sectorClassification.getDescription() != null) addInfoText(sectorClassification.getDescription());

Expand Down Expand Up @@ -415,42 +408,34 @@ public Collection<AmpSector> getChoices(String input) {

Collection<AmpSector> choices = super.getChoices(input);
Set<AmpSector> choices2 = new HashSet<>(choices);
// List<AmpSector> newChoices = (List<AmpSector>)searchSectors.getModelParams().get(AmpSectorSearchModel.PARAM.NEW_CHOICES);
// List<AmpSector> sectorChoices = (List<AmpSector>)searchSectors.getModelParams().get(AmpSectorSearchModel.PARAM.SECTOR_CHOICES);
// if (newChoices!=null)
// {
// choices= newChoices;
// choices2= new HashSet<>(newChoices);
// }

logger.info("Choices here: " + choices);
searchSectors.getModelParams().put(AmpSectorSearchModel.PARAM.NEW_CHOICES, choices);




if (sectorClassification.getName().equals(AmpClassificationConfiguration.SECONDARY_CLASSIFICATION_CONFIGURATION_NAME)) {
List<AmpActivitySector> selectedSectors = (List<AmpActivitySector>) searchSectors.getModelParams().get(AmpSectorSearchModel.PARAM.DST_SECTOR_SELECTED);

if (selectedSectors != null) {
List<AmpActivitySector> selectedSectors = (List<AmpActivitySector>) this.getModelParams().get(AmpSectorSearchModel.PARAM.DST_SECTOR_SELECTED);

if (selectedSectors!= null) {
for (AmpSector choice : choices2) {
for (AmpActivitySector ampActivitySector : selectedSectors) {
if (Objects.equals(choice.getAmpSectorId(), ampActivitySector.getSectorId().getAmpSectorId())) {
for (AmpActivitySector ampActivitySector: selectedSectors)
{
if (Objects.equals(choice.getAmpSectorId(), ampActivitySector.getSectorId().getAmpSectorId()))
{
choices.remove(choice);
break;
}
}
}
}
}




extracted(choices);
}

return choices;
}



@Override
public Integer getChoiceLevel(AmpSector choice) {
int i = 0;
Expand Down Expand Up @@ -484,47 +469,6 @@ public Integer getChoiceLevel(AmpSector choice) {

add(this.searchSectors);




}

public void extracted(Collection<AmpSector> choices) {
if (sectorClassification.getName().equals(AmpClassificationConfiguration.SECONDARY_CLASSIFICATION_CONFIGURATION_NAME)) {
AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);

if (choices.size()==1)
{
for (AmpSector secondarySector : choices) {
AmpActivitySector newSector = new AmpActivitySector();
newSector.setSectorId(secondarySector);
newSector.setActivityId(setModel.getObject().iterator().next().getActivityId()); // Assuming activityId is the same
newSector.setClassificationConfig(sectorClassification);
searchSectors.getModelParams().computeIfAbsent(AmpSectorSearchModel.PARAM.DST_SECTOR_SELECTED,
k -> new ArrayList<>());
((List<AmpActivitySector>)searchSectors.getModelParams().get(AmpSectorSearchModel.PARAM.DST_SECTOR_SELECTED)).add(newSector);

setModel.getObject().add(newSector);
}

target.add(list.getParent());

}

List<AmpSector> srcSectorSelected = (List<AmpSector>)searchSectors.getModelParams().get(AmpSectorSearchModel.PARAM.SRC_SECTOR_SELECTED);

updateBasedOnData(srcSectorSelected);

logger.info("Target: "+target);
if (target != null) {
target.add(searchSectors);
// triggerUpdateEvent(setModel.getObject(), sectorClassification);
target.add(this);
// refreshTable(target);
}


}
}


Expand Down

0 comments on commit e4d6ea0

Please sign in to comment.