-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added uniqueness check on creation and amendment
- Loading branch information
1 parent
75bf1ab
commit 199d5e6
Showing
7 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...n/java/uk/co/compendiumdev/challenge/practicemodes/simpleapi/AddMoreItemsIfNecessary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package uk.co.compendiumdev.challenge.practicemodes.simpleapi; | ||
|
||
import uk.co.compendiumdev.thingifier.api.http.HttpApiRequest; | ||
import uk.co.compendiumdev.thingifier.api.http.HttpApiResponse; | ||
import uk.co.compendiumdev.thingifier.apiconfig.ThingifierApiConfig; | ||
import uk.co.compendiumdev.thingifier.application.httpapimessagehooks.HttpApiRequestHook; | ||
import uk.co.compendiumdev.thingifier.core.EntityRelModel; | ||
import uk.co.compendiumdev.thingifier.core.domain.instances.ERInstanceData; | ||
import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstanceCollection; | ||
|
||
public class AddMoreItemsIfNecessary implements HttpApiRequestHook { | ||
|
||
private final EntityRelModel erModel; | ||
|
||
public AddMoreItemsIfNecessary(EntityRelModel eRmodel){ | ||
this.erModel = eRmodel; | ||
} | ||
|
||
@Override | ||
public HttpApiResponse run(HttpApiRequest request, ThingifierApiConfig config) { | ||
|
||
ERInstanceData instanceData = erModel.getInstanceData(EntityRelModel.DEFAULT_DATABASE_NAME); | ||
if(instanceData!=null){ | ||
EntityInstanceCollection collection = instanceData. | ||
getInstanceCollectionForEntityNamed("item"); | ||
if(collection != null && collection.countInstances()<5) { | ||
erModel.populateDatabase(EntityRelModel.DEFAULT_DATABASE_NAME); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters