Ein Beispiel wie Java-Code nicht aussehen sollte:
private Collection<CollectableEntityObject<PK>> readDependants(CollectableMasterData<PK> clct) { if (clct == null) { return Collections.<CollectableEntityObject<PK>>emptyList(); } Collection<CollectableEntityObject<PK>> lstclctmd = new ArrayList<CollectableEntityObject<PK>>(); for(CollectableEntityObject<?> clcteo : clct.getDependantCollectableMasterDataMap().getValues(getEntityAndForeignKeyField().getDependentKey())) lstclctmd.add((CollectableEntityObject<PK>)clcteo); if (isHistoricalView() // must be an historical view of parent controller. ) { //&& !clct.getMasterDataCVO().getEntityObject().getDependants().getData(this.getEntityAndForeignKeyFieldName().getEntityName()).isEmpty()) { lstclctmd = CollectionUtils.transform(clct.getMasterDataCVO().getEntityObject().getDependents().getData( getEntityAndForeignKeyField().getDependentKey()), new CollectableEntityObject.MakeCollectable(CollectableEOEntityClientProvider.getInstance().getCollectableEntity( getEntityAndForeignKeyField().getEntity()))); } else { if (lstclctmd.isEmpty() && clct.getId() != null) { final Collection<EntityObjectVO<PK>> collmdvo = (Collection<EntityObjectVO<PK>>) ((clct == null) ? new ArrayList<EntityObjectVO<PK>>() : MasterDataDelegate.getInstance().getDependentDataCollection(getCollectableEntity().getUID(), getForeignKeyFieldUID(), getSubForm().getMapParams(), clct.getPrimaryKey())); lstclctmd = CollectionUtils.transform(collmdvo, new CollectableEntityObject.MakeCollectable(this.getCollectableEntity())); clct.getDependantCollectableMasterDataMap().addValues(getEntityAndForeignKeyField().getDependentKey(), lstclctmd); } } return lstclctmd; }
Verbesserte Strukur:
private Collection<CollectableEntityObject<PK>> readDependants(CollectableMasterData<PK> clct) { if (clct == null) { return Collections.<CollectableEntityObject<PK>>emptyList(); } if (isHistoricalView()) { // must be an historical view of parent controller. return readDependentsForHistoricalView(clct); } IDependentKey dependentKey = getEntityAndForeignKeyField().getDependentKey(); Collection<CollectableEntityObject<PK>> loadedDependents = RigidUtils.uncheckedCast(clct.getDependantCollectableMasterDataMap().getValues(dependentKey)); if (!loadedDependents.isEmpty() || clct.getPrimaryKey() == null) { return new ArrayList<CollectableEntityObject<PK>>(loadedDependents); } final Collection<EntityObjectVO<PK>> collmdvo = MasterDataDelegate.getInstance() .getDependentDataCollection(getCollectableEntity().getUID(), getForeignKeyFieldUID(), getSubForm().getMapParams(), clct.getPrimaryKey()); Collection<CollectableEntityObject<PK>> lstclctmd = CollectionUtils.transform(collmdvo, new CollectableEntityObject.MakeCollectable(getCollectableEntity())); clct.getDependantCollectableMasterDataMap().addValues(dependentKey, lstclctmd); return lstclctmd; }
Überblick
Inhalte