Home › Forum › Nuclos Entwicklung › Makros und Regeln › BusinessObjektProvider: Zugriff auf erzeugte BOs › BusinessObjektProvider: Zugriff auf erzeugte BOs
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