Added initial implementation of entity EOModelBundle export, including various utility methods and refactoring and such

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@630279 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David E. Jones
2008-02-22 18:17:21 +00:00
parent e2f24153a8
commit e8d61ef0b7
13 changed files with 595 additions and 120 deletions
@@ -0,0 +1,116 @@
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
package org.ofbiz.entityext;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javolution.util.FastList;
import javolution.util.FastSet;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.model.ModelViewEntity;
/**
* EntityEcaUtil
*/
public class EntityGroupUtil {
public static final String module = EntityGroupUtil.class.getName();
public static Set<String> getEntityNamesByGroup(String entityGroupId, GenericDelegator delegator) throws GenericEntityException {
Set<String> entityNames = FastSet.newInstance();
List entitySyncGroupIncludes = delegator.findByAnd("EntitySyncInclGrpDetailView", UtilMisc.toMap("entityGroupId", entityGroupId));
List<ModelEntity> modelEntities = getModelEntitiesFromRecords(entitySyncGroupIncludes, delegator);
for (ModelEntity modelEntity: modelEntities) {
entityNames.add(modelEntity.getEntityName());
}
return entityNames;
}
public static List<ModelEntity> getModelEntitiesFromRecords(List<GenericValue> entityGroupEntryValues, GenericDelegator delegator) throws GenericEntityException {
List<ModelEntity> entityModelToUseList = FastList.newInstance();
Iterator entityNameIter = delegator.getModelReader().getEntityNamesIterator();
while (entityNameIter.hasNext()) {
String entityName = (String) entityNameIter.next();
ModelEntity modelEntity = delegator.getModelEntity(entityName);
// if view-entity, throw it out
if (modelEntity instanceof ModelViewEntity) {
continue;
}
// if it doesn't have either or both of the two update stamp fields, throw it out
if (!modelEntity.isField(ModelEntity.STAMP_FIELD) || !modelEntity.isField(ModelEntity.STAMP_TX_FIELD)) {
continue;
}
// if there are no includes records, always include; otherwise check each one to make sure at least one matches
if (entityGroupEntryValues.size() == 0) {
entityModelToUseList.add(modelEntity);
} else {
// we have different types of include applications: ESIA_INCLUDE, ESIA_EXCLUDE, ESIA_ALWAYS
// if we find an always we can break right there because this will always be include regardless of excludes, etc
// if we find an include or exclude we have to finish going through the rest of them just in case there is something that overrides it (ie an exclude for an include or an always for an exclude)
boolean matchesInclude = false;
boolean matchesExclude = false;
boolean matchesAlways = false;
Iterator<GenericValue> entitySyncIncludeIter = entityGroupEntryValues.iterator();
while (entitySyncIncludeIter.hasNext()) {
GenericValue entitySyncInclude = entitySyncIncludeIter.next();
String entityOrPackage = entitySyncInclude.getString("entityOrPackage");
boolean matches = false;
if (entityName.equals(entityOrPackage)) {
matches = true;
} else if (modelEntity.getPackageName().startsWith(entityOrPackage)) {
matches = true;
}
if (matches) {
if ("ESIA_INCLUDE".equals(entitySyncInclude.getString("applEnumId"))) {
matchesInclude = true;
} else if ("ESIA_EXCLUDE".equals(entitySyncInclude.getString("applEnumId"))) {
matchesExclude = true;
} else if ("ESIA_ALWAYS".equals(entitySyncInclude.getString("applEnumId"))) {
matchesAlways = true;
break;
}
}
}
if (matchesAlways || (matchesInclude && !matchesExclude)) {
// make sure this log message is not checked in uncommented:
//Debug.log("In runEntitySync adding [" + modelEntity.getEntityName() + "] to list of Entities to sync", module);
entityModelToUseList.add(modelEntity);
}
}
}
return entityModelToUseList;
}
}
@@ -49,6 +49,7 @@ import org.ofbiz.entity.serialize.XmlSerializer;
import org.ofbiz.entity.transaction.GenericTransactionException;
import org.ofbiz.entity.transaction.TransactionUtil;
import org.ofbiz.entity.util.EntityListIterator;
import org.ofbiz.entityext.EntityGroupUtil;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GeneralServiceException;
import org.ofbiz.service.GenericServiceException;
@@ -843,69 +844,13 @@ public class EntitySyncContext {
}
/** prepare a list of all entities we want to synchronize: remove all view-entities and all entities that don't match the patterns attached to this EntitySync */
protected List makeEntityModelToUseList() throws GenericEntityException {
List entityModelToUseList = new LinkedList();
List entitySyncIncludes = entitySync.getRelated("EntitySyncInclude");
protected List<ModelEntity> makeEntityModelToUseList() throws GenericEntityException {
List<GenericValue> entitySyncIncludes = entitySync.getRelated("EntitySyncInclude");
// get these ones as well, and just add them to the main list, it will have an extra field but that shouldn't hurt anything in the code below
List entitySyncGroupIncludes = entitySync.getRelated("EntitySyncInclGrpDetailView");
List<GenericValue> entitySyncGroupIncludes = entitySync.getRelated("EntitySyncInclGrpDetailView");
entitySyncIncludes.addAll(entitySyncGroupIncludes);
Iterator entityNameIter = delegator.getModelReader().getEntityNamesIterator();
while (entityNameIter.hasNext()) {
String entityName = (String) entityNameIter.next();
ModelEntity modelEntity = delegator.getModelEntity(entityName);
// if view-entity, throw it out
if (modelEntity instanceof ModelViewEntity) {
continue;
}
// if it doesn't have either or both of the two update stamp fields, throw it out
if (!modelEntity.isField(ModelEntity.STAMP_FIELD) || !modelEntity.isField(ModelEntity.STAMP_TX_FIELD)) {
continue;
}
// if there are no includes records, always include; otherwise check each one to make sure at least one matches
if (entitySyncIncludes.size() == 0) {
entityModelToUseList.add(modelEntity);
} else {
// we have different types of include applications: ESIA_INCLUDE, ESIA_EXCLUDE, ESIA_ALWAYS
// if we find an always we can break right there because this will always be include regardless of excludes, etc
// if we find an include or exclude we have to finish going through the rest of them just in case there is something that overrides it (ie an exclude for an include or an always for an exclude)
boolean matchesInclude = false;
boolean matchesExclude = false;
boolean matchesAlways = false;
Iterator entitySyncIncludeIter = entitySyncIncludes.iterator();
while (entitySyncIncludeIter.hasNext()) {
GenericValue entitySyncInclude = (GenericValue) entitySyncIncludeIter.next();
String entityOrPackage = entitySyncInclude.getString("entityOrPackage");
boolean matches = false;
if (entityName.equals(entityOrPackage)) {
matches = true;
} else if (modelEntity.getPackageName().startsWith(entityOrPackage)) {
matches = true;
}
if (matches) {
if ("ESIA_INCLUDE".equals(entitySyncInclude.getString("applEnumId"))) {
matchesInclude = true;
} else if ("ESIA_EXCLUDE".equals(entitySyncInclude.getString("applEnumId"))) {
matchesExclude = true;
} else if ("ESIA_ALWAYS".equals(entitySyncInclude.getString("applEnumId"))) {
matchesAlways = true;
break;
}
}
}
if (matchesAlways || (matchesInclude && !matchesExclude)) {
// make sure this log message is not checked in uncommented:
//Debug.log("In runEntitySync adding [" + modelEntity.getEntityName() + "] to list of Entities to sync", module);
entityModelToUseList.add(modelEntity);
}
}
}
List<ModelEntity> entityModelToUseList = EntityGroupUtil.getModelEntitiesFromRecords(entitySyncIncludes, delegator);
if (Debug.infoOn()) Debug.logInfo("In makeEntityModelToUseList for EntitySync with ID [" + entitySync.get("entitySyncId") + "] syncing " + entityModelToUseList.size() + " entities", module);
return entityModelToUseList;