Skip to content

Commit

Permalink
Close #146
Browse files Browse the repository at this point in the history
  • Loading branch information
Open Lowcode SAS committed Jun 10, 2020
1 parent 2548db2 commit 7c6433d
Show file tree
Hide file tree
Showing 10 changed files with 654 additions and 467 deletions.
7 changes: 6 additions & 1 deletion src/org/openlowcode/client/action/CActionDataLoc.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019 [Open Lowcode SAS](https://openlowcode.com/)
* Copyright (c) 2019-2020 [Open Lowcode SAS](https://openlowcode.com/)
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -32,6 +32,7 @@ public class CActionDataLoc extends Named {
public static final String TEXT_TYPE = "TXT";
public static final String OBJ_TYPE = "OBJ";
public static final String OBJ_ID_TYPE = "OID";
public static final String OBJ_MS_ID_TYPE = "OMI";
public static final String CHOICE_TYPE = "CHT";
public static final String MULTI_CHOICE_TYPE = "MLC";
public static final String ARRAY_PREFIX = "ARR/";
Expand All @@ -58,6 +59,8 @@ public CActionDataLoc(MessageReader reader) throws OLcRemoteException, IOExcepti
typesupported = true;
if (this.type.compareTo(OBJ_ID_TYPE) == 0)
typesupported = true;
if (this.type.compareTo(OBJ_MS_ID_TYPE) == 0)
typesupported=true;
if (this.type.compareTo(CHOICE_TYPE) == 0)
typesupported = true;
if (this.type.compareTo(MULTI_CHOICE_TYPE) == 0)
Expand All @@ -81,6 +84,8 @@ public CActionDataLoc(MessageReader reader) throws OLcRemoteException, IOExcepti
typesupported = true;
if (subtype.compareTo(CHOICE_TYPE) == 0)
typesupported = true;
if (subtype.compareTo(OBJ_MS_ID_TYPE) == 0)
typesupported = true;
}
if (!typesupported)
throw new RuntimeException("the type put in the action field " + this.getName()
Expand Down
38 changes: 38 additions & 0 deletions src/org/openlowcode/client/graphic/widget/CObjectArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.openlowcode.tools.structure.ObjectDataEltType;
import org.openlowcode.tools.structure.ObjectIdDataElt;
import org.openlowcode.tools.structure.ObjectIdDataEltType;
import org.openlowcode.tools.structure.ObjectMasterIdDataElt;
import org.openlowcode.tools.structure.ObjectMasterIdDataEltType;
import org.openlowcode.tools.structure.SimpleDataElt;
import org.openlowcode.tools.structure.TextDataElt;
import org.openlowcode.tools.structure.TextDataEltType;
Expand Down Expand Up @@ -894,6 +896,21 @@ public DataElt getDataElt(DataEltType type, String eltname, String objectfieldna
ObjectIdDataElt objectid = new ObjectIdDataElt(eltname, textfield.getPayload());
return objectid;
}

if (type instanceof ObjectMasterIdDataEltType) {
if (objectfieldname == null)
throw new RuntimeException("objectid field should have an objectfieldname");
ObjectDataElt object = this.thistable.getSelectionModel().getSelectedItem().getObject();
SimpleDataElt field = object.lookupEltByName(objectfieldname);
if (field == null)
throw new RuntimeException(
"field not found " + objectfieldname + ", available fields = " + object.dropFieldNames());
if (!(field instanceof TextDataElt))
throw new RuntimeException("field for name = " + objectfieldname + " is not text");
TextDataElt textfield = (TextDataElt) field;
ObjectMasterIdDataElt objectid = new ObjectMasterIdDataElt(eltname, textfield.getPayload());
return objectid;
}

if (type instanceof TextDataEltType) {
TextDataElt updatenote = new TextDataElt(eltname, this.updatenotecomment);
Expand Down Expand Up @@ -977,6 +994,27 @@ public DataElt getDataElt(DataEltType type, String eltname, String objectfieldna
return output;
}


if (payloadtypeinarray instanceof ObjectMasterIdDataEltType) {
Iterator<ObjectTableRow> selectedobjects = this.thistable.getSelectionModel().getSelectedItems()
.iterator();
ArrayDataElt<ObjectMasterIdDataElt> output = new ArrayDataElt<ObjectMasterIdDataElt>(eltname, payloadtypeinarray);
while (selectedobjects.hasNext()) {
ObjectDataElt thisobject = selectedobjects.next().getObject();
SimpleDataElt field = thisobject.lookupEltByName(objectfieldname);
if (field == null)
throw new RuntimeException("field not found " + objectfieldname + ", available fields = "
+ thisobject.dropFieldNames());
if (!(field instanceof TextDataElt))
throw new RuntimeException("field for name = " + objectfieldname + " is not text");
TextDataElt textfield = (TextDataElt) field;
ObjectMasterIdDataElt objectid = new ObjectMasterIdDataElt(eltname, textfield.getPayload());
output.addElement(objectid);
}
return output;
}


}
// add here treatment of array element.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
+ "(blanklinkforaddtoleft" + linkobjectvariable + "s.getObjectInput());");
sg.wl(" createlinkactionforaddtoleft" + linkobjectvariable + "s.setRight" + rightobjectvariable
+ "id(" + rightobjectvariable + "searchforaddtoleft" + linkobjectvariable
+ "s.getresultarray().getAttributeArrayInput(" + rightobjectclass + ".getLinkobjecttomasterrightidMarker()));");
+ "s.getresultarray().getAttributeArrayInput(" + rightobjectclass + ".getIdMarker()));");
sg.wl(" ");
sg.wl(" SActionButton createlinkbuttonforaddtoleft" + linkobjectvariable
+ " = new SActionButton(\"Add Link\", createlinkactionforaddtoleft" + linkobjectvariable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/********************************************************************************
* Copyright (c) 2020 [Open Lowcode SAS](https://openlowcode.com/)
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0 .
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/

package org.openlowcode.design.data.properties.basic;

import java.io.IOException;
Expand All @@ -16,6 +26,16 @@
import org.openlowcode.design.pages.PageDefinition;
import org.openlowcode.tools.misc.NamedList;

/**
* The property for an object that is left for a link to master relationship
*
* @author <a href="https://openlowcode.com/" rel="nofollow">Open Lowcode
* SAS</a>
*
* @param <E> current object
* @param <F> link to master object
* @since 1.9
*/
public class LeftForLinkToMaster<E extends DataObjectDefinition, F extends DataObjectDefinition>
extends
Property<LeftForLinkToMaster<E, F>> {
Expand Down Expand Up @@ -111,7 +131,9 @@ public DataObjectDefinition getLinkObjectDefinition() {
public LinkObjectToMaster<E, F> getLinkObjectProperty() {
DataObjectDefinition linkobject = linkdataobject;
@SuppressWarnings("unchecked")
LinkObjectToMaster<E, F> linkobjectproperty = (LinkObjectToMaster<E, F>) linkobject.getPropertyByName("LINKOBJECTTOMASTER");
LinkObjectToMaster<
E,
F> linkobjectproperty = (LinkObjectToMaster<E, F>) linkobject.getPropertyByName("LINKOBJECTTOMASTER");
if (linkobjectproperty == null)
throw new RuntimeException("link object does not have property");
return linkobjectproperty;
Expand Down Expand Up @@ -318,15 +340,16 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
.formatForAttribute(parentproperty.getRightObjectForLink().getName());
String rightobjectclass = StringFormatter
.formatForJavaClass(parentproperty.getRightObjectForLink().getName());

// ---- temporary code.
DisplayLinkAsAttributeFromLeftObject<E, F> attributeasleft = null;
/*
@SuppressWarnings("unchecked")
DisplayLinkAsAttributeFromLeftObject<E, F> attributeasleft = (DisplayLinkAsAttributeFromLeftObject<
E, F>) parentproperty.getLinkObjectProperty().getBusinessRuleByName("DISPLAYASATTRIBUTEFROMLEFT");
*/

* @SuppressWarnings("unchecked") DisplayLinkAsAttributeFromLeftObject<E, F>
* attributeasleft = (DisplayLinkAsAttributeFromLeftObject< E, F>)
* parentproperty.getLinkObjectProperty().getBusinessRuleByName(
* "DISPLAYASATTRIBUTEFROMLEFT");
*/

if (attributeasleft == null) {
// -------------------------------------------------------------------------------------------------
// show link as table. This is the classical display
Expand All @@ -346,7 +369,7 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
sg.wl(" this);");
sg.wl(" left" + linkobjectvariable + "s.addDisplayProfile(" + linkobjectclass + "Definition.get"
+ linkobjectclass + "Definition().getDisplayProfileHideleftobjectfields());");

sg.wl(" left" + linkobjectvariable + "s.setMinFieldPriority(-900);");
sg.wl(" left" + linkobjectvariable + "s.setWarningForUnsavedEdition();");
sg.wl(" AtgMassupdate" + linkobjectvariable + "andshowleftAction.ActionRef updateleft"
+ linkobjectvariable + "s = AtgMassupdate" + linkobjectvariable
Expand All @@ -366,7 +389,8 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
+ linkobjectvariable + "action = AtgShow" + rightobjectvariable
+ "Action.get().getActionRef();");
sg.wl(" showright" + rightobjectvariable + "for" + linkobjectvariable + "action.setId(left"
+ linkobjectvariable + "s.getAttributeInput(" + linkobjectclass + ".getRgmsidMarker()));");
+ linkobjectvariable + "s.getAttributeInput(" + linkobjectclass
+ ".getLinkobjecttomasterrightidMarker()));");
sg.wl(" left" + linkobjectvariable + "s.addDefaultAction(showright" + rightobjectvariable + "for"
+ linkobjectvariable + "action);");
sg.wl(" ");
Expand Down Expand Up @@ -414,8 +438,8 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
+ "s = new SObjectDisplay<" + linkobjectclass + ">(\"BLANK"
+ linkobject.getName().toUpperCase() + "FORADD\",");

sg.wl(" this.getLeftforlinktomasterfor" + linkobjectvariable + "blankforadd(), " + linkobjectclass
+ ".getDefinition(),this, false);");
sg.wl(" this.getLeftforlinktomasterfor" + linkobjectvariable + "blankforadd(), "
+ linkobjectclass + ".getDefinition(),this, false);");
sg.wl(" blanklinkforaddtoleft" + linkobjectvariable + "s.setHideReadOnly();");
sg.wl(" ");
sg.wl(" addtoleft" + linkobjectvariable + "s.addElement(blanklinkforaddtoleft" + linkobjectvariable
Expand Down Expand Up @@ -462,7 +486,7 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
+ "button);");
sg.wl(" " + locationname + ".addElement(left" + linkobjectvariable + "buttonbar);");
sg.wl(" " + locationname + ".addElement(left" + linkobjectvariable + "s);");
}
}

}

Expand Down
47 changes: 45 additions & 2 deletions src/org/openlowcode/server/data/DataObjectDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Function;
import java.util.logging.Logger;

import org.openlowcode.tools.messages.MessageWriter;
Expand Down Expand Up @@ -282,12 +283,12 @@ public QueryCondition getUniversalQueryCondition(DataObjectPropertyDefinition<E>
* @return generates a data object id array template.
*/
public abstract DataObjectId<E>[] generateIdArrayTemplate();

/**
* @return generates a data object master id array template
*/
public abstract DataObjectMasterId<E>[] generateMasterIdArrayTemplate();

/**
* @return a blank object
*/
Expand Down Expand Up @@ -335,6 +336,48 @@ public <Z extends Object> JoinQueryConditionDefinition<Z> generateJoinQueryDefin
this, operator);
}

/**
* generates a join query definition
*
* @param maintable the main table to join this
* object into
* @param maintablefield the field to use on main table
* @param propertyname name of the property to join in
* @param propertyfield field of the property
* @param sidetablesuffix suffix to add to this table
* @param operator typically equals for a foreign
* key
* @param additionalqueryconditiononsideobject additional condition on side
* object (e.g. only get latest
* version)
* @return a join query condition
* @since 1.9
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public <Z extends Object> JoinQueryConditionDefinition<Z> generateJoinQueryDefinition(
StoredTableSchema maintable,
StoredFieldSchema<Z> maintablefield,
String propertyname,
String propertyfield,
String sidetablesuffix,
QueryOperator<Z> operator,
Function<String, QueryCondition> additionalqueryconditiononsideobject) {
DataObjectPropertyDefinition<E> propertydefinition = propertydeflist.lookupOnName(propertyname);
if (propertydefinition == null)
throw new RuntimeException("did not find property with name = '" + propertyname + "', available list = "
+ propertydeflist.dropNameList());
FieldSchema<?> field = propertydefinition.getFieldSchemaByName(propertyfield);
if (field == null)
throw new RuntimeException("did not find field with name '" + propertyfield + ", , available list = "
+ propertydefinition.dropfieldnamelist());
if (!(field instanceof StoredFieldSchema))
throw new RuntimeException("definition of externalfield joinquerycondition " + maintablefield.getName()
+ " is referencing another external field : " + field);
StoredFieldSchema<?> storedfield = (StoredFieldSchema<?>) field;
return new JoinQueryConditionDefinition(maintable, maintablefield, tableschema, sidetablesuffix, storedfield,
this, operator, additionalqueryconditiononsideobject);
}

/**
* checks if the property with the given name exists
*
Expand Down
Loading

0 comments on commit 7c6433d

Please sign in to comment.