Home › Forum › Nuclos Entwicklung › Makros und Regeln › BusinessObjektProvider: Zugriff auf erzeugte BOs
- Dieses Thema hat 4 Antworten und 2 Teilnehmer, und wurde zuletzt aktualisiert vor 6 Jahren, 10 Monaten von
Hans Dengel.
-
AutorBeiträge
-
30 Dezember 2016 um 17:14 Uhr #9259
Hans Dengel
TeilnehmerHallo Forum
ich habe in einer Regel mit BusinessObjektProvider.insert(NewBO) ein neues BO erstellt. Wie kann ich jetzt in der Regel auf das neue BO zugreifen. Gibt es irgendeine Methode die ID des erzeugten BOs oder das erzeugte BO selbst (und dann mit BO.getId() die ID) zu bekommen. Oder wird über die insert Methode das übergebene newBO mit der Id versehen und ich könnte direkt mit dem newBO weiterarbeiten ?
Die ID brauche ich für ein Referenzfeld in einem anderen BO der Regel. Irgendwelche Vorschläge ?mfg
Hans
30 Dezember 2016 um 17:44 Uhr #9260Fry123
TeilnehmerDie Angabe im Wiki ist veraltet/fehlerhaft. Wenn du hier schaust: http://api.nuclos.de/org/nuclos/api/provider/BusinessObjectProvider.html
wirst du feststellen das die insert methode ein Long zurück liefert. Das ist null wenn das Objekt nicht erstellt werden konnte sonst ist es die ID des Objekts welches erstellt worden ist.
MFG
30 Dezember 2016 um 18:21 Uhr #9261Hans Dengel
TeilnehmerDanke, das macht schon mehr Sinn.
Peobiere ich mal aus
7 Januar 2017 um 23:41 Uhr #9309Hans Dengel
TeilnehmerHallo Fry123, Hallo Forum,
habe das mal ausprobiert.
Der Quelcode sieht dann etwa so aus:
package org.nuclet.businessentity;
import org.nuclos.api.rule.GenerateFinalRule;
import org.nuclos.api.context.GenerateContext;
import org.nuclos.api.annotation.Rule;
import org.nuclos.api.exception.BusinessException;import org.nuclos.api.provider.QueryProvider;
import org.nuclos.api.businessobject.Query;
import org.nuclos.api.provider.BusinessObjectProvider;import org.nuclet.businessentity.NWEntityType;
import org.nuclet.businessentity.NWEntity;
import java.util.List;
/** @name
* @description
* @usage
* @change
*/
@Rule(name=“GEN_CreateNetworkEntityAndChilds“, description=“Erzeugt aus einer Netzelementtyp ein konkretes Netzelement“)
public class GENCreateNetworkEntityAndChilds implements GenerateFinalRule {private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(„MyRules“);
public void createNetworkEntity(NWEntityType source, NWEntity target) {
/** query all children of parent entity for further processing **/
Query qryChildren = QueryProvider.create(NWEntityType.class);
qryChildren.where(NWEntityType.ParentId.eq(source.getId()));
LOGGER.info(„ParentId=“ + source.getId());
List children = QueryProvider.execute(qryChildren);
for (NWEntityType child : children) {
/** create new child NWEntity **/
LOGGER.info(„childId=“ + child.getId());
NWEntity newEntity = new NWEntity();
newEntity.setClassnameId(child.getClassnameId());
//newEntity.setPorttypeId(child.getPorttypeId());
newEntity.setName(child.getName());
newEntity.setParentId(target.getId());
//newEntity.setEntitytypeId(child.getId());
Long newEntityId = 0L;newEntityId = BusinessObjectProvider.insert(newEntity);
LOGGER.info(„NewEntityId=“ + newEntityId);/** get new NWEntityBO as input for recursive call of createNewNetworkEntity() **/
if (newEntityId != 0) {
NWEntity newtarget = QueryProvider.getById(NWEntity.class, newEntityId);
createNetworkEntity(child, newtarget);
}
}
}public void generateFinal(GenerateContext context) throws BusinessException {
NWEntityType parentEntityType = context.getSourceObject(NWEntityType.class);
NWEntity parentEntity = context.getTargetObject(NWEntity.class);
createNetworkEntity(parentEntityType, parentEntity);LOGGER.info(„Test.main“);
parentEntity.setNotice(„done“);
/** maybe put sommething into notice field later **/
}
}nur so kompiliert es nicht :
GENCreateNetworkEntityAndChilds.java:42: unreported exception org.nuclos.api.exception.BusinessException; must be caught or declared to be thrown
Wenn ich das gance in einen try catch Block einschliesse compiliert alles aber es wird ein exception geworfen beim Ausführen:
017-01-07 20:03:25,917 INFO [MyRules] – ParentId=40001027
2017-01-07 20:03:25,921 INFO [MyRules] – childId=40001393
2017-01-07 20:03:25,925 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,925 INFO [MyRules] – childId=40001395
2017-01-07 20:03:25,928 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,928 INFO [MyRules] – childId=40001397
2017-01-07 20:03:25,931 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,932 INFO [MyRules] – childId=40001399
2017-01-07 20:03:25,934 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,935 INFO [MyRules] – childId=40001401
2017-01-07 20:03:25,937 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,938 INFO [MyRules] – childId=40001403
2017-01-07 20:03:25,940 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,940 INFO [MyRules] – childId=40001405
2017-01-07 20:03:25,943 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,943 INFO [MyRules] – childId=40001407
2017-01-07 20:03:25,946 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,946 INFO [MyRules] – childId=40001409
2017-01-07 20:03:25,949 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,949 INFO [MyRules] – childId=40001411
2017-01-07 20:03:25,952 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,952 INFO [MyRules] – childId=40001413
2017-01-07 20:03:25,955 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,955 INFO [MyRules] – childId=40001415
2017-01-07 20:03:25,959 INFO [MyRules] – creation failed:org.nuclos.api.exception.BusinessException: common.exception.novabitcreateexception
2017-01-07 20:03:25,959 INFO [org.nuclet.businessentity.GENCreateNetworkEntityAndChilds] – Test
2017-01-07 20:03:25,959 INFO [MyRules] – Test.mainSieht irgendjemand wo der Fehler liegen könnte, oder das Verständnisproblem ?
MFG
Hans
8 Januar 2017 um 21:56 Uhr #9310Hans Dengel
TeilnehmerHallo,
Problem gelöst.
Wenn man die Methode
public void createNetworkEntity(NWEntityType source, NWEntity target)
ändert in
public void createNetworkEntity(NWEntityType source, NWEntity target) throws BusinessExceptionfunktioniert alles wie gewünscht.
Grüsse
Hans
-
AutorBeiträge