Home Forum Nuclos Entwicklung Makros und Regeln Server Regel(API-basiert) Server Regel(API-basiert)

#6410
Christian Dumhart
Teilnehmer

Hallo und Danke für die rasche Antwort!

Sorry aber für mich als Anfänger sind das zu wenig Informationen um meinen Fehler zu finden ;(

Ich hab einmal eine View vom RegelManagement und von Server Regel (API basierend) angehängt.

Hier der Sourcecode von den Server Regeln im einzelnen (sind alles nur tests u. tlw. vom Forum kopiert)

test nummernkreis:

import org.nuclos.common.collect.collectable.searchcondition.*;
import org.nuclos.server.masterdata.valueobject.*;
import org.nuclos.server.ruleengine.*;
import java.util.*;

/** @name
* @description
* @usage
* @change
*/
@Rule(name="NummernkreisKlasse", description="test nummernkreis")
public class NummernkreisKlasse implements CustomRule{

/**
* ...
*
* @author Markus Glitzner (alias Hugo)
* @version 2011-10-30
*
* @param sEntity the entity name e.g. Aufträge
* @param sField the entity's number field e.g. auftragsnummer
* @param sKey the name of the number range e.g. Auftragsnummer
*
*/
public static void NextValue(RuleInterface server, String sEntity, String sField, String sKey) throws NuclosBusinessRuleException {

//only if the object is new
if (server.isObjectNew()){

//get the id of the numbering entry
Integer id;
id = getId(server, "Nummernkreis", "Name", sKey);

if (id == null) {
throw new NuclosBusinessRuleException("Der Nummernkreis " + sKey + " ist nicht vorhanden!");
}else{
//get the MasterDataVO of Nummernkreis
MasterDataVO item = server.getMasterData("Nummernkreise", id);
throw new NuclosBusinessRuleException("Der Nummernkreis " + sKey + " vorhanden!");
//get the values from Nummernkreis
//String prefix = (String)Nz(item.getField("prefix"), "");
//Integer padcount = (Integer)Nz(item.getField("padcount"), 0);
//Integer nextvalue = (Integer)Nz(item.getField("nextvalue"), 1);

//set the new number to the called entity
//String format = String.format("%%0%dd", padcount);
//server.setFieldValue(sEntity, sField, prefix + String.format(format, nextvalue));

//set the new value in Nummernkreis
//server.setFieldValue("Nummernkreise", id, "nextvalue", nextvalue+1);
}
}
}

private static Integer getId(RuleInterface server, String sEntity, String sField, String sKey) {
CollectableComparison cond = org.nuclos.common.SearchConditionUtils.newMDComparison(org.nuclos.server.common.MasterDataMetaCache.getInstance().getMetaData(sEntity), sField, ComparisonOperator.EQUAL, sKey);
Collection ids = server.getMasterDataIds(sEntity, new org.nuclos.server.genericobject.searchcondition.CollectableSearchExpression(cond));

if (!ids.isEmpty()) {
return (Integer)ids.iterator().next();
}else{
return null;
}
}

private static Object Nz(Object o, Object defaultvalue) {
if (o != null) {
return o;
}else{
return defaultvalue;
}
}

void custom(CustomContext context)
throws BusinessException
{

}

}

test für update

package org.nuclet.businessentity;

import org.nuclos.api.rule.UpdateFinalRule;
import org.nuclos.api.context.UpdateContext;
import org.nuclos.api.annotation.Rule;
import org.nuclos.api.exception.BusinessException;

/** @name
* @description
* @usage
* @change
*/
@Rule(name="testupdate", description="test für update")
public class testupdate implements UpdateFinalRule {

public void updateFinal(UpdateContext context) throws BusinessException {
}
}

test Nummernkreis:

package org.nuclet.businessentity;

import org.nuclos.api.rule.UpdateRule;
import org.nuclos.api.context.UpdateContext;
import org.nuclos.api.annotation.Rule;
import org.nuclos.api.exception.BusinessException;

/** @name
* @description
* @usage
* @change
*/
@Rule(name="testNummer", description="test Nummernkreis")
public class testNummer implements UpdateRule {

public void update(UpdateContext context) throws BusinessException {
}
}

Im Regel Management taucht nur die Alte Regel „test“ auf die anderen die mit Server Regel erstellt worden sidn leider nicht.

Lege ich z.B. im Regel Management unter Benutzeraktion mit der rechten Maus eine neue Regel „test3“ an und speicher diese ab mach ein update im regel Managment passiert nichts.

Hier die Regel test3:

package org.nuclet.businessentity;

import org.nuclos.api.rule.CustomRule;
import org.nuclos.api.context.CustomContext;
import org.nuclos.api.annotation.Rule;
import org.nuclos.api.exception.BusinessException;

/** @name
* @description
* @usage
* @change
*/
@Rule(name="test3", description="")
public class test3 implements CustomRule {

public void custom(CustomContext context) throws BusinessException {
}
}

Was mach ich falsch? Danke! Christian