passing string to java action and retriving List output
0
// This file was generated by Mendix Modeler. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à , etc. are supported in comments. package aerisk.actions; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.webui.CustomJavaAction; import com.mendix.systemwideinterfaces.core.IMendixObject; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.LinkedHashSet; public class ExtractKeywords extends CustomJavaAction<java.util.List<IMendixObject>> { private java.util.List<IMendixObject> __Keywords; private java.util.List<aerisk.proxies.Keyword> Keywords; private java.util.List<IMendixObject> __NonKeywordParameter1; private java.util.List<aerisk.proxies.NonKeyword> NonKeywordParameter1; private IMendixObject __ExtractString; private aerisk.proxies.ExtractfromArticle ExtractString; public ExtractKeywords(IContext context, java.util.List<IMendixObject> Keywords, java.util.List<IMendixObject> NonKeywordParameter1, IMendixObject ExtractString) { super(context); this.__Keywords = Keywords; this.__NonKeywordParameter1 = NonKeywordParameter1; this.__ExtractString = ExtractString; } @java.lang.Override public java.util.List<IMendixObject> executeAction() throws Exception { this.Keywords = new java.util.ArrayList<aerisk.proxies.Keyword>(); if (__Keywords != null) for (IMendixObject __KeywordsElement : __Keywords) this.Keywords.add(aerisk.proxies.Keyword.initialize(getContext(), __KeywordsElement)); this.NonKeywordParameter1 = new java.util.ArrayList<aerisk.proxies.NonKeyword>(); if (__NonKeywordParameter1 != null) for (IMendixObject __NonKeywordParameter1Element : __NonKeywordParameter1) this.NonKeywordParameter1.add(aerisk.proxies.NonKeyword.initialize(getContext(), __NonKeywordParameter1Element)); this.ExtractString = __ExtractString == null ? null : aerisk.proxies.ExtractfromArticle.initialize(getContext(), __ExtractString); // BEGIN USER CODE String article = this.ExtractString.toString(); IMendixObject[] arrSplit = Arrays.stream(article.split(" ")).distinct().toArray(IMendixObject[]::new); if (arrSplit != null) for (IMendixObject __KeywordListElements : arrSplit) this.Keywords.add(aerisk.proxies.Keyword.initialize(getContext(), __KeywordListElements)); java.util.List<IMendixObject> finalKeywords = new ArrayList<IMendixObject>(); this.__Keywords.addAll((Collection<? extends IMendixObject>) this.Keywords); finalKeywords.addAll(__Keywords); return finalKeywords; //throw new com.mendix.systemwideinterfaces.MendixRuntimeException("Java action was not implemented"); // END USER CODE } /** * Returns a string representation of this action */ @java.lang.Override public java.lang.String toString() { return "ExtractKeywords"; } // BEGIN EXTRA CODE // END EXTRA CODE } Task to be performed in the Java Action. String Split as List (List1) Merge another List (List2) with List Created in step 1 Remove Duplicates list items Remove List (List3) from List1 Return Final List Please suggest. Edited Example: <Step1> List1 = {Vijay,Manoj,Vivek} (List Created After String Split ) <Step1> List2={Pradip,Rahul,Manoj} After Merge List2 = {Vijay,Manoj,Vivek,Pradip,Rahul,Manoj} <Step3> Remove Duplicates List2 = {Vijay,Manoj,Vivek,Pradip,Rahul} (Notice Manoj is removed, It was duplicate) <Step4> Remove List3 from List2 List3 = {Pradip,is,are} List2 = {Vijay,Manoj,Vivek,Rahul} (Notice Pradip is also removed) <Step5> Return the final List List2 = {Vijay,Manoj,Vivek,Rahul}
asked
2019-05-03
vijaybir singh
3 answers
0
answered
2019-05-03
Erwin 't Hoen
0
Trying to figure out what the functional goal is of your 5 steps. Seems to me you will end up with a list containing the List1-items that also exist in List2.
answered
2019-05-04
Tim v Steenbergen
0
Do you really have to do this in Java? Can you not define a Entity lets say ‘ASTRING’ with a fields ‘astring’.
Then use the mendix list operations to do your tasks?
FYI: I am presuming you got into java via a microflow in which you converted a domain object into a comma separated string!?
answered
2019-05-04
Ganesh Acharya