Home Forum Nuclos Entwicklung Makros und Regeln BusinessObjektProvider: Zugriff auf erzeugte BOs

Ansicht von 5 Beiträgen - 1 bis 5 (von insgesamt 5)
  • Autor
    Beiträge
  • #9259
    Hans Dengel
    Teilnehmer

    Hallo 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

    #9260
    Fry123
    Teilnehmer

    Die 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

    #9261
    Hans Dengel
    Teilnehmer

    Danke, das macht schon mehr Sinn.

    Peobiere ich mal aus

    #9309
    Hans Dengel
    Teilnehmer

    Hallo 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.main

    Sieht irgendjemand wo der Fehler liegen könnte, oder das Verständnisproblem ?

    MFG

    Hans

    #9310
    Hans Dengel
    Teilnehmer

    Hallo,

    Problem gelöst.
    Wenn man die Methode
    public void createNetworkEntity(NWEntityType source, NWEntity target)
    ändert in
    public void createNetworkEntity(NWEntityType source, NWEntity target) throws BusinessException

    funktioniert alles wie gewünscht.

    Grüsse

    Hans

Ansicht von 5 Beiträgen - 1 bis 5 (von insgesamt 5)