use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class ContentManagementWorker method getAuthorContent.
public static GenericValue getAuthorContent(Delegator delegator, String contentId) {
GenericValue authorContent = null;
try {
List<String> assocTypes = UtilMisc.toList("AUTHOR");
// TODO check if we want contentTypes to be filled/used, else this should be removed
List<String> contentTypes = null;
Map<String, Object> results = ContentServicesComplex.getAssocAndContentAndDataResourceCacheMethod(delegator, contentId, null, "To", null, null, assocTypes, contentTypes, Boolean.TRUE, null, null);
List<GenericValue> valueList = UtilGenerics.checkList(results.get("entityList"));
if (valueList.size() > 0) {
GenericValue value = valueList.get(0);
authorContent = delegator.makeValue("Content");
authorContent.setPKFields(value);
authorContent.setNonPKFields(value);
}
} catch (GenericEntityException | MiniLangException e) {
Debug.logError(e.getMessage(), module);
}
return authorContent;
}
use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class ContentServicesComplex method getAssocAndContentAndDataResourceCache.
/*
* A service that returns a list of ContentAssocDataResourceViewFrom/To views that are
* associated with the passed in contentId. Other conditions are also applied, including:
* a list of contentAssocTypeIds or contentTypeIds that the result set views must match.
* A direction (From or To - case insensitive).
* From and thru dates or date strings.
* A mapKey value.
*/
public static Map<String, Object> getAssocAndContentAndDataResourceCache(DispatchContext dctx, Map<String, ? extends Object> context) {
Delegator delegator = dctx.getDelegator();
List<String> assocTypes = UtilGenerics.checkList(context.get("assocTypes"));
String assocTypesString = (String) context.get("assocTypesString");
if (UtilValidate.isNotEmpty(assocTypesString)) {
List<String> lst = StringUtil.split(assocTypesString, "|");
if (assocTypes == null) {
assocTypes = new LinkedList<String>();
}
assocTypes.addAll(lst);
}
List<String> contentTypes = UtilGenerics.checkList(context.get("contentTypes"));
String contentTypesString = (String) context.get("contentTypesString");
if (UtilValidate.isNotEmpty(contentTypesString)) {
List<String> lst = StringUtil.split(contentTypesString, "|");
if (contentTypes == null) {
contentTypes = new LinkedList<String>();
}
contentTypes.addAll(lst);
}
Timestamp fromDate = (Timestamp) context.get("fromDate");
String fromDateStr = (String) context.get("fromDateStr");
String contentId = (String) context.get("contentId");
String direction = (String) context.get("direction");
String mapKey = (String) context.get("mapKey");
String contentAssocPredicateId = (String) context.get("contentAssocPredicateId");
Boolean nullThruDatesOnly = (Boolean) context.get("nullThruDatesOnly");
Map<String, Object> results = null;
try {
results = getAssocAndContentAndDataResourceCacheMethod(delegator, contentId, mapKey, direction, fromDate, fromDateStr, assocTypes, contentTypes, nullThruDatesOnly, contentAssocPredicateId, null);
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
} catch (MiniLangException e2) {
return ServiceUtil.returnError(e2.getMessage());
}
return results;
}
use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class ServiceArtifactInfo method populateUsedEntities.
protected void populateUsedEntities() throws GeneralException {
// populate entitiesUsedByThisService and for each the reverse-associate cache in the aif
if ("simple".equals(this.modelService.engineName)) {
// we can do something with this!
SimpleMethod simpleMethodToCall = null;
try {
simpleMethodToCall = SimpleMethod.getSimpleMethod(this.modelService.location, this.modelService.invoke, null);
} catch (MiniLangException e) {
Debug.logWarning("Error getting Simple-method [" + this.modelService.invoke + "] in [" + this.modelService.location + "] referenced in service [" + this.modelService.name + "]: " + e.toString(), module);
}
if (simpleMethodToCall == null) {
Debug.logWarning("Simple-method [" + this.modelService.invoke + "] in [" + this.modelService.location + "] referenced in service [" + this.modelService.name + "] not found", module);
return;
}
ArtifactInfoContext aic = new ArtifactInfoContext();
simpleMethodToCall.gatherArtifactInfo(aic);
populateEntitiesFromNameSet(aic.getEntityNames());
} else if ("java".equals(this.modelService.engineName)) {
String fullClassPathAndFile = UtilJavaParse.findRealPathAndFileForClass(this.modelService.location);
if (fullClassPathAndFile != null) {
String javaFile = null;
try {
javaFile = FileUtil.readTextFile(fullClassPathAndFile, true).toString();
} catch (FileNotFoundException e) {
Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
return;
} catch (IOException e) {
Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
return;
}
javaFile = UtilJavaParse.stripComments(javaFile);
int methodBlockStart = UtilJavaParse.findServiceMethodBlockStart(this.modelService.invoke, javaFile);
int methodBlockEnd = UtilJavaParse.findEndOfBlock(methodBlockStart, javaFile);
Set<String> allEntityNameSet = UtilJavaParse.findEntityUseInBlock(methodBlockStart, methodBlockEnd, javaFile);
populateEntitiesFromNameSet(allEntityNameSet);
}
} else if ("group".equals(this.modelService.engineName)) {
// nothing to do, there won't be entities referred to in these
}
}
use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class ServiceArtifactInfo method populateCalledServices.
protected void populateCalledServices() throws GeneralException {
// populate servicesCalledByThisService and for each the reverse-associate cache in the aif
if ("simple".equals(this.modelService.engineName)) {
// we can do something with this!
SimpleMethod simpleMethodToCall = null;
try {
simpleMethodToCall = SimpleMethod.getSimpleMethod(this.modelService.location, this.modelService.invoke, null);
} catch (MiniLangException e) {
Debug.logWarning("Error getting Simple-method [" + this.modelService.invoke + "] in [" + this.modelService.location + "] referenced in service [" + this.modelService.name + "]: " + e.toString(), module);
}
if (simpleMethodToCall == null) {
Debug.logWarning("Simple-method [" + this.modelService.invoke + "] in [" + this.modelService.location + "] referenced in service [" + this.modelService.name + "] not found", module);
return;
}
ArtifactInfoContext aic = new ArtifactInfoContext();
simpleMethodToCall.gatherArtifactInfo(aic);
populateServicesFromNameSet(aic.getServiceNames());
} else if ("java".equals(this.modelService.engineName)) {
String fullClassPathAndFile = UtilJavaParse.findRealPathAndFileForClass(this.modelService.location);
if (fullClassPathAndFile != null) {
String javaFile = null;
try {
javaFile = FileUtil.readTextFile(fullClassPathAndFile, true).toString();
} catch (FileNotFoundException e) {
Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
return;
} catch (IOException e) {
Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
return;
}
javaFile = UtilJavaParse.stripComments(javaFile);
int methodBlockStart = UtilJavaParse.findServiceMethodBlockStart(this.modelService.invoke, javaFile);
int methodBlockEnd = UtilJavaParse.findEndOfBlock(methodBlockStart, javaFile);
Set<String> allServiceNameSet = UtilJavaParse.findServiceCallsInBlock(methodBlockStart, methodBlockEnd, javaFile);
populateServicesFromNameSet(allServiceNameSet);
}
} else if ("group".equals(this.modelService.engineName)) {
Set<String> allServiceNameSet = new HashSet<String>();
GroupModel groupModel = modelService.internalGroup;
if (groupModel == null) {
groupModel = ServiceGroupReader.getGroupModel(this.modelService.location);
}
if (groupModel != null) {
List<GroupServiceModel> groupServiceModels = groupModel.getServices();
for (GroupServiceModel groupServiceModel : groupServiceModels) {
allServiceNameSet.add(groupServiceModel.getName());
}
}
populateServicesFromNameSet(allServiceNameSet);
}
}
use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class EntityData method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
List<Object> messages = errorListFma.get(methodContext.getEnvMap());
if (messages == null) {
messages = new LinkedList<Object>();
errorListFma.put(methodContext.getEnvMap(), messages);
}
String location = this.locationFse.expandString(methodContext.getEnvMap());
Delegator delegator = getDelegator(methodContext);
URL dataUrl = null;
try {
dataUrl = FlexibleLocation.resolveLocation(location, methodContext.getLoader());
} catch (MalformedURLException e) {
messages.add("Could not find Entity Data document in resource: " + location + "; error was: " + e.toString());
}
if (dataUrl == null) {
messages.add("Could not find Entity Data document in resource: " + location);
}
if ("assert".equals(mode)) {
try {
EntityDataAssert.assertData(dataUrl, delegator, messages);
} catch (Exception e) {
String xmlError = "Error checking/asserting XML Resource \"" + dataUrl.toExternalForm() + "\"; Error was: " + e.getMessage();
messages.add(xmlError);
Debug.logWarning(e, xmlError, module);
}
} else {
try {
EntitySaxReader reader = null;
if (timeout > 0) {
reader = new EntitySaxReader(delegator, timeout);
} else {
reader = new EntitySaxReader(delegator);
}
reader.parse(dataUrl);
} catch (Exception e) {
String xmlError = "Error loading XML Resource \"" + dataUrl.toExternalForm() + "\"; Error was: " + e.getMessage();
messages.add(xmlError);
Debug.logWarning(e, xmlError, module);
}
}
return true;
}
Aggregations