Skip to content

Commit

Permalink
Merge pull request #555 from metasfresh/gh551-api
Browse files Browse the repository at this point in the history
verify if lookup value is still valid #551
  • Loading branch information
metas-ts authored Aug 30, 2017
2 parents 062b08b + 9979ef4 commit 8dd9123
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[![Join the chat at https://gitter.im/metasfresh/metasfresh](https://badges.gitter.im/metasfresh/metasfresh.svg)](https://gitter.im/metasfresh/metasfresh?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Krihelimeter](http://krihelinator.xyz/badge/metasfresh/metasfresh-webui-api)](http://krihelinator.xyz)

#metasfresh-webui-api
# metasfresh-webui-api

This repo contains the API service of our webui. The frontend can be found in its [own repository](https://github.com/metasfresh/metasfresh-webui-frontend).

#Some notes for developers:
# Some notes for developers:

* one can run it from eclipse
* the `main` method is located at `/metasfresh-webui-api/src/main/java/de/metas/ui/web/WebRestApiApplication.java`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@ public List<JSONDocument> processParametersChangeEvents(
final IProcessInstancesRepository instancesRepository = getRepository(processId);

return Execution.callInNewExecution("", () -> {
final IDocumentChangesCollector changesCollector = Execution.getCurrentDocumentChangesCollectorOrNull();

final IDocumentChangesCollector changesCollector = Execution.getCurrentDocumentChangesCollectorOrNull(); // get our collector to fill with the changes that we will record

instancesRepository.forProcessInstanceWritable(pinstanceId, changesCollector, processInstance -> {

processInstance.processParameterValueChanges(events, REASON_Value_DirectSetFromCommitAPI);
return null; // void
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static IDocumentChangesCollector getCurrentDocumentChangesCollector()
}

/**
* @return actual {@link IDocumentChangesCollector} or {@link NullDocumentChangesCollector}
* @return actual {@link IDocumentChangesCollector} or {@link NullDocumentChangesCollector}. Never returns {@code null}.
*/
public static IDocumentChangesCollector getCurrentDocumentChangesCollectorOrNull()
{
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/de/metas/ui/web/window/model/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ public void processValueChange(final String fieldName, final Object value, final
}
}

public void processValueChanges(final List<JSONDocumentChangedEvent> events, final ReasonSupplier reason) throws DocumentFieldReadonlyException
public void processValueChanges(@NonNull final List<JSONDocumentChangedEvent> events, final ReasonSupplier reason) throws DocumentFieldReadonlyException
{
for (final JSONDocumentChangedEvent event : events)
{
Expand Down Expand Up @@ -1451,6 +1451,21 @@ else if (DependencyType.LookupValues == triggeringDependencyType)
final boolean lookupValuesStaled = documentField.setLookupValuesStaled(triggeringFieldName);
if (lookupValuesStaled && !lookupValuesStaledOld)
{
// https://github.com/metasfresh/metasfresh-webui-api/issues/551 check if we can leave the old value as it is
final Object valueOld = documentField.getValue();
if (valueOld != null)
{
final boolean currentValueStillValid = documentField.getLookupValues() // because we did setLookupValuesStaled(), this causes a reload
.stream()
.anyMatch(value -> Objects.equals(value, valueOld)); // check if the current value is still value after we reloaded the list
if(!currentValueStillValid)
{
documentField.setValue(null, changesCollector);
changesCollector.collectValueIfChanged(documentField, valueOld, reason);
}
}

// https://github.com/metasfresh/metasfresh-webui-frontend/issues/1165 - the value was not stale, but now it is => notify the frontend so it shall invalidate its cache
changesCollector.collectLookupValuesStaled(documentField, reason);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface IDocumentChangesCollector
/**
* Mark the changes of given document path as primary changes.
*
* Primary changes are those changes which are on a document which was directly references by REST endpoint.
* Primary changes are those changes which are on a document which was directly referenced by REST endpoint.
*
* @param documentPath
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ default DocumentPath getDocumentPath()

void setDisplayed(LogicExpressionResult displayed);

/**
* Notify this instance that it's lookup values are staled. So next time they are needed, they need to be reloaded.
*
* @param triggeringFieldName
* @return
*/
boolean setLookupValuesStaled(String triggeringFieldName);

LookupValuesList getLookupValues();
Expand Down

0 comments on commit 8dd9123

Please sign in to comment.