Nuclos event rule Object generation (final): interface, GenerateContext, structure, assignment in the server rule manager, example code (Java). |
Language: Deutsch · English
Event rule „Object generation (final)“: interface, context and an example – how to react to this Nuclos event.
Auf dieser Seite |
This server-side rule runs after a successful object generation. It can be assigned to a object generator.
Skeleton of the rule class (the rule editor creates it automatically):
package org.nuclet.lager;
import org.nuclos.api.rule.GenerateFinalRule;
import org.nuclos.api.context.GenerateContext;
import org.nuclos.api.annotation.Rule;
import org.nuclos.api.exception.BusinessException;
/
** @name
* @description
* @usage
* @change
*/
@Rule(name="Objektgenerierung im Anschluss", description="Objektgenerierung im Anschluss")
public class ObjektgenerierungImAnschluss implements GenerateFinalRule {
public void generateFinal(GenerateContext context) throws BusinessException {
}
} |
The context |
Assign it to the target via drag-and-drop in the server rule manager. Optionally restrict execution to a status or an action; control the order with the arrow buttons.
package org.nuclet.company;
import org.nuclos.api.rule.GenerateRule;
import org.nuclos.api.context.GenerateContext;
import org.nuclos.api.annotation.Rule;
import org.nuclos.api.exception.BusinessException;
import java.util.Collection;
/** @name
* @description
* @usage
* @change
*/
@Rule(name="BestellungErstellen", description="BestellungErstellen")
public class BestellungErstellen implements GenerateRule {
public void generate(GenerateContext context) throws BusinessException {
Collection<Anfrage> sourceObjects = context.getSourceObjects(Anfrage.class);
int sumOfArticles = 0;
for (Anfrage a: sourceObjects) {
// How many articles are in this inquiry
sumOfArticles += a.getAnfrageposition().size();
}
Bestellung targetObject = context.getTargetObject(Bestellung.class);
// create new history entry
BestellungHistory newHistory = new BestellungHistory();
newHistory.setBestellungId(targetObject.getId());
newHistory.setBemerkung(sumOfArticles + " Einträge");
// save new entry
BusinessObjectProvider.insert(newHistory);
}
} |