Search in sources :

Example 16 with MiniLangException

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;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) MiniLangException(org.apache.ofbiz.minilang.MiniLangException)

Example 17 with MiniLangException

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;
}
Also used : Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) Timestamp(java.sql.Timestamp)

Example 18 with MiniLangException

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
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) FileNotFoundException(java.io.FileNotFoundException) SimpleMethod(org.apache.ofbiz.minilang.SimpleMethod) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) IOException(java.io.IOException) ArtifactInfoContext(org.apache.ofbiz.minilang.artifact.ArtifactInfoContext)

Example 19 with MiniLangException

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);
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) GroupServiceModel(org.apache.ofbiz.service.group.GroupServiceModel) FileNotFoundException(java.io.FileNotFoundException) SimpleMethod(org.apache.ofbiz.minilang.SimpleMethod) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) GroupModel(org.apache.ofbiz.service.group.GroupModel) IOException(java.io.IOException) ArtifactInfoContext(org.apache.ofbiz.minilang.artifact.ArtifactInfoContext) HashSet(java.util.HashSet)

Example 20 with MiniLangException

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;
}
Also used : EntitySaxReader(org.apache.ofbiz.entity.util.EntitySaxReader) MalformedURLException(java.net.MalformedURLException) Delegator(org.apache.ofbiz.entity.Delegator) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) MiniLangException(org.apache.ofbiz.minilang.MiniLangException)

Aggregations

MiniLangException (org.apache.ofbiz.minilang.MiniLangException)27 GenericValue (org.apache.ofbiz.entity.GenericValue)13 Locale (java.util.Locale)9 HashMap (java.util.HashMap)8 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)8 MiniLangRuntimeException (org.apache.ofbiz.minilang.MiniLangRuntimeException)8 LinkedList (java.util.LinkedList)7 Delegator (org.apache.ofbiz.entity.Delegator)7 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)6 HttpSession (javax.servlet.http.HttpSession)5 SimpleMethod (org.apache.ofbiz.minilang.SimpleMethod)5 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)5 Timestamp (java.sql.Timestamp)4 Map (java.util.Map)4 IOException (java.io.IOException)3 MethodOperation (org.apache.ofbiz.minilang.method.MethodOperation)3 BreakElementException (org.apache.ofbiz.minilang.method.envops.Break.BreakElementException)3 ContinueElementException (org.apache.ofbiz.minilang.method.envops.Continue.ContinueElementException)3 FileNotFoundException (java.io.FileNotFoundException)2 HashSet (java.util.HashSet)2