Search in sources :

Example 61 with GenericEntityException

use of org.apache.ofbiz.entity.GenericEntityException in project ofbiz-framework by apache.

the class ICalConverter method makeCalendar.

protected static Calendar makeCalendar(GenericValue workEffort, Map<String, Object> context) throws GenericEntityException {
    String iCalData = null;
    GenericValue iCalValue = workEffort.getRelatedOne("WorkEffortIcalData", false);
    if (iCalValue != null) {
        iCalData = iCalValue.getString("icalData");
    }
    boolean newCalendar = true;
    Calendar calendar = null;
    if (iCalData == null) {
        if (Debug.verboseOn())
            Debug.logVerbose("iCalendar Data not found, creating new Calendar", module);
        calendar = new Calendar();
    } else {
        if (Debug.verboseOn())
            Debug.logVerbose("iCalendar Data found, using saved Calendar", module);
        StringReader reader = new StringReader(iCalData);
        CalendarBuilder builder = new CalendarBuilder();
        try {
            calendar = builder.build(reader);
            newCalendar = false;
        } catch (Exception e) {
            Debug.logError(e, "Error while parsing saved iCalendar, creating new iCalendar: ", module);
            calendar = new Calendar();
        }
    }
    PropertyList propList = calendar.getProperties();
    replaceProperty(propList, prodId);
    replaceProperty(propList, new XProperty(workEffortIdXPropName, workEffort.getString("workEffortId")));
    if (newCalendar) {
        propList.add(Version.VERSION_2_0);
        propList.add(CalScale.GREGORIAN);
        // TODO: Get time zone from publish properties value
        java.util.TimeZone tz = java.util.TimeZone.getDefault();
        TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
        net.fortuna.ical4j.model.TimeZone timezone = registry.getTimeZone(tz.getID());
        calendar.getComponents().add(timezone.getVTimeZone());
    }
    return calendar;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) XProperty(net.fortuna.ical4j.model.property.XProperty) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) Calendar(net.fortuna.ical4j.model.Calendar) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) URISyntaxException(java.net.URISyntaxException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) ParserException(net.fortuna.ical4j.data.ParserException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GeneralException(org.apache.ofbiz.base.util.GeneralException) ValidationException(net.fortuna.ical4j.model.ValidationException) IOException(java.io.IOException) PropertyList(net.fortuna.ical4j.model.PropertyList) StringReader(java.io.StringReader)

Example 62 with GenericEntityException

use of org.apache.ofbiz.entity.GenericEntityException in project ofbiz-framework by apache.

the class ICalConverter method storePartyAssignments.

protected static ResponseProperties storePartyAssignments(String workEffortId, Component component, Map<String, Object> context) {
    ResponseProperties responseProps = null;
    Map<String, Object> serviceMap = new HashMap<>();
    List<Property> partyList = new LinkedList<>();
    partyList.addAll(UtilGenerics.checkList(component.getProperties("ATTENDEE"), Property.class));
    partyList.addAll(UtilGenerics.checkList(component.getProperties("CONTACT"), Property.class));
    partyList.addAll(UtilGenerics.checkList(component.getProperties("ORGANIZER"), Property.class));
    for (Property property : partyList) {
        String partyId = fromXParameter(property.getParameters(), partyIdXParamName);
        if (partyId == null) {
            serviceMap.clear();
            String address = property.getValue();
            if (address.toUpperCase(Locale.getDefault()).startsWith("MAILTO:")) {
                address = address.substring(7);
            }
            serviceMap.put("address", address);
            Map<String, Object> result = invokeService("findPartyFromEmailAddress", serviceMap, context);
            partyId = (String) result.get("partyId");
            if (partyId == null) {
                continue;
            }
            replaceParameter(property.getParameters(), toXParameter(partyIdXParamName, partyId));
        }
        serviceMap.clear();
        serviceMap.put("workEffortId", workEffortId);
        serviceMap.put("partyId", partyId);
        serviceMap.put("roleTypeId", fromRoleMap.get(property.getName()));
        Delegator delegator = (Delegator) context.get("delegator");
        List<GenericValue> assignments = null;
        try {
            assignments = EntityQuery.use(delegator).from("WorkEffortPartyAssignment").where(serviceMap).filterByDate().queryList();
            if (assignments.size() == 0) {
                serviceMap.put("statusId", "PRTYASGN_OFFERED");
                serviceMap.put("fromDate", new Timestamp(System.currentTimeMillis()));
                invokeService("assignPartyToWorkEffort", serviceMap, context);
            }
        } catch (GenericEntityException e) {
            responseProps = ICalWorker.createPartialContentResponse(e.getMessage());
            break;
        }
    }
    return responseProps;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) HashMap(java.util.HashMap) Timestamp(java.sql.Timestamp) LinkedList(java.util.LinkedList) Delegator(org.apache.ofbiz.entity.Delegator) ResponseProperties(org.apache.ofbiz.workeffort.workeffort.ICalWorker.ResponseProperties) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property)

Example 63 with GenericEntityException

use of org.apache.ofbiz.entity.GenericEntityException in project ofbiz-framework by apache.

the class ParametricSearch method makeCategoryFeatureLists.

public static Map<String, List<GenericValue>> makeCategoryFeatureLists(String productCategoryId, Delegator delegator, int perTypeMaxSize) {
    Map<String, Map<String, GenericValue>> productFeaturesByTypeMap = new HashMap<String, Map<String, GenericValue>>();
    try {
        List<GenericValue> productFeatureCategoryAppls = EntityQuery.use(delegator).from("ProductFeatureCategoryAppl").where("productCategoryId", productCategoryId).cache(true).queryList();
        productFeatureCategoryAppls = EntityUtil.filterByDate(productFeatureCategoryAppls, true);
        if (productFeatureCategoryAppls != null) {
            for (GenericValue productFeatureCategoryAppl : productFeatureCategoryAppls) {
                List<GenericValue> productFeatures = EntityQuery.use(delegator).from("ProductFeature").where("productFeatureCategoryId", productFeatureCategoryAppl.get("productFeatureCategoryId")).cache(true).queryList();
                for (GenericValue productFeature : productFeatures) {
                    String productFeatureTypeId = productFeature.getString("productFeatureTypeId");
                    Map<String, GenericValue> featuresByType = productFeaturesByTypeMap.get(productFeatureTypeId);
                    if (featuresByType == null) {
                        featuresByType = new HashMap<String, GenericValue>();
                        productFeaturesByTypeMap.put(productFeatureTypeId, featuresByType);
                    }
                    if (featuresByType.size() < perTypeMaxSize) {
                        featuresByType.put(productFeature.getString("productFeatureId"), productFeature);
                    }
                }
            }
        }
    } catch (GenericEntityException e) {
        Debug.logError(e, "Error getting feature categories associated with the category with ID: " + productCategoryId, module);
    }
    try {
        List<GenericValue> productFeatureCatGrpAppls = EntityQuery.use(delegator).from("ProductFeatureCatGrpAppl").where("productCategoryId", productCategoryId).cache(true).queryList();
        productFeatureCatGrpAppls = EntityUtil.filterByDate(productFeatureCatGrpAppls, true);
        if (productFeatureCatGrpAppls != null) {
            for (GenericValue productFeatureCatGrpAppl : productFeatureCatGrpAppls) {
                List<GenericValue> productFeatureGroupAppls = EntityQuery.use(delegator).from("ProductFeatureGroupAppl").where("productFeatureGroupId", productFeatureCatGrpAppl.get("productFeatureGroupId")).cache(true).queryList();
                for (GenericValue productFeatureGroupAppl : productFeatureGroupAppls) {
                    GenericValue productFeature = EntityQuery.use(delegator).from("ProductFeature").where("productFeatureId", productFeatureGroupAppl.get("productFeatureId")).cache().queryOne();
                    String productFeatureTypeId = productFeature.getString("productFeatureTypeId");
                    Map<String, GenericValue> featuresByType = productFeaturesByTypeMap.get(productFeatureTypeId);
                    if (featuresByType == null) {
                        featuresByType = new HashMap<String, GenericValue>();
                        productFeaturesByTypeMap.put(productFeatureTypeId, featuresByType);
                    }
                    if (featuresByType.size() < perTypeMaxSize) {
                        featuresByType.put(productFeature.getString("productFeatureId"), productFeature);
                    }
                }
            }
        }
    } catch (GenericEntityException e) {
        Debug.logError(e, "Error getting feature groups associated with the category with ID: " + productCategoryId, module);
    }
    // now before returning, order the features in each list by description
    Map<String, List<GenericValue>> productFeaturesByTypeMapSorted = new HashMap<String, List<GenericValue>>();
    for (Map.Entry<String, Map<String, GenericValue>> entry : productFeaturesByTypeMap.entrySet()) {
        List<GenericValue> sortedFeatures = EntityUtil.orderBy(entry.getValue().values(), UtilMisc.toList("description", "defaultSequenceNum"));
        productFeaturesByTypeMapSorted.put(entry.getKey(), sortedFeatures);
    }
    return productFeaturesByTypeMapSorted;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) HashMap(java.util.HashMap) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 64 with GenericEntityException

use of org.apache.ofbiz.entity.GenericEntityException in project ofbiz-framework by apache.

the class FrameImage method addImageFrame.

public static Map<String, Object> addImageFrame(DispatchContext dctx, Map<String, ? extends Object> context) throws IOException {
    Map<String, Object> result;
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Delegator delegator = dctx.getDelegator();
    String imageServerPath = FlexibleStringExpander.expandString(EntityUtilProperties.getPropertyValue("catalog", "image.management.path", delegator), context);
    String imageServerUrl = FlexibleStringExpander.expandString(EntityUtilProperties.getPropertyValue("catalog", "image.management.url", delegator), context);
    String nameOfThumb = FlexibleStringExpander.expandString(EntityUtilProperties.getPropertyValue("catalog", "image.management.nameofthumbnail", delegator), context);
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    String productId = (String) context.get("productId");
    String imageName = (String) context.get("imageName");
    String imageWidth = (String) context.get("imageWidth");
    String imageHeight = (String) context.get("imageHeight");
    Locale locale = (Locale) context.get("locale");
    if (UtilValidate.isEmpty(context.get("frameContentId")) || UtilValidate.isEmpty(context.get("frameDataResourceId"))) {
        result = ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "ProductImageFrameContentIdRequired", locale));
        result.putAll(context);
    }
    if (UtilValidate.isEmpty(context.get("imageWidth")) || UtilValidate.isEmpty(context.get("imageHeight"))) {
        result = ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "ProductImageWidthAndHeightRequired", locale));
        result.putAll(context);
    }
    String frameContentId = (String) context.get("frameContentId");
    String frameDataResourceId = (String) context.get("frameDataResourceId");
    String frameImageName = null;
    try {
        GenericValue contentDataResourceView = EntityQuery.use(delegator).from("ContentDataResourceView").where("contentId", frameContentId, "drDataResourceId", frameDataResourceId).queryOne();
        frameImageName = contentDataResourceView.getString("contentName");
    } catch (GenericEntityException gee) {
        Debug.logError(gee, module);
        result = ServiceUtil.returnError(gee.getMessage());
        result.putAll(context);
    }
    if (UtilValidate.isNotEmpty(imageName)) {
        // Image Frame
        BufferedImage bufImg1 = ImageIO.read(new File(imageServerPath + "/" + productId + "/" + imageName));
        BufferedImage bufImg2 = ImageIO.read(new File(imageServerPath + "/frame/" + frameImageName));
        int bufImgType;
        if (BufferedImage.TYPE_CUSTOM == bufImg1.getType()) {
            bufImgType = BufferedImage.TYPE_INT_ARGB_PRE;
        } else {
            bufImgType = bufImg1.getType();
        }
        int width = Integer.parseInt(imageWidth);
        int height = Integer.parseInt(imageHeight);
        Map<String, Object> contentCtx = new HashMap<>();
        contentCtx.put("contentTypeId", "DOCUMENT");
        contentCtx.put("userLogin", userLogin);
        Map<String, Object> contentResult = new HashMap<>();
        try {
            contentResult = dispatcher.runSync("createContent", contentCtx);
            if (ServiceUtil.isError(contentResult)) {
                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(contentResult));
            }
        } catch (GenericServiceException e) {
            Debug.logError(e, module);
            result = ServiceUtil.returnError(e.getMessage());
            result.putAll(context);
        }
        Map<String, Object> contentThumb = new HashMap<>();
        contentThumb.put("contentTypeId", "DOCUMENT");
        contentThumb.put("userLogin", userLogin);
        Map<String, Object> contentThumbResult = new HashMap<>();
        try {
            contentThumbResult = dispatcher.runSync("createContent", contentThumb);
            if (ServiceUtil.isError(contentThumbResult)) {
                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(contentThumbResult));
            }
        } catch (GenericServiceException e) {
            Debug.logError(e, module);
            result = ServiceUtil.returnError(e.getMessage());
            result.putAll(context);
        }
        String contentIdThumb = (String) contentThumbResult.get("contentId");
        String contentId = (String) contentResult.get("contentId");
        String filenameToUse = (String) contentResult.get("contentId") + ".jpg";
        String filenameTouseThumb = (String) contentResult.get("contentId") + nameOfThumb + ".jpg";
        Image newImg1 = bufImg1.getScaledInstance(width, height, Image.SCALE_SMOOTH);
        Image newImg2 = bufImg2.getScaledInstance(width, height, Image.SCALE_SMOOTH);
        BufferedImage bufNewImg = combineBufferedImage(newImg1, newImg2, bufImgType);
        String mimeType = imageName.substring(imageName.lastIndexOf('.') + 1);
        ImageIO.write(bufNewImg, mimeType, new File(imageServerPath + "/" + productId + "/" + filenameToUse));
        double imgHeight = bufNewImg.getHeight();
        double imgWidth = bufNewImg.getWidth();
        Map<String, Object> resultResize = ImageManagementServices.resizeImageThumbnail(bufNewImg, imgHeight, imgWidth);
        ImageIO.write((RenderedImage) resultResize.get("bufferedImage"), mimeType, new File(imageServerPath + "/" + productId + "/" + filenameTouseThumb));
        String imageUrlResource = imageServerUrl + "/" + productId + "/" + filenameToUse;
        String imageUrlThumb = imageServerUrl + "/" + productId + "/" + filenameTouseThumb;
        ImageManagementServices.createContentAndDataResource(dctx, userLogin, filenameToUse, imageUrlResource, contentId, "image/jpeg");
        ImageManagementServices.createContentAndDataResource(dctx, userLogin, filenameTouseThumb, imageUrlThumb, contentIdThumb, "image/jpeg");
        Map<String, Object> createContentAssocMap = new HashMap<>();
        createContentAssocMap.put("contentAssocTypeId", "IMAGE_THUMBNAIL");
        createContentAssocMap.put("contentId", contentId);
        createContentAssocMap.put("contentIdTo", contentIdThumb);
        createContentAssocMap.put("userLogin", userLogin);
        createContentAssocMap.put("mapKey", "100");
        try {
            Map<String, Object> serviceResult = dispatcher.runSync("createContentAssoc", createContentAssocMap);
            if (ServiceUtil.isError(serviceResult)) {
                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));
            }
        } catch (GenericServiceException e) {
            Debug.logError(e, module);
            result = ServiceUtil.returnError(e.getMessage());
            result.putAll(context);
        }
        Map<String, Object> productContentCtx = new HashMap<>();
        productContentCtx.put("productId", productId);
        productContentCtx.put("productContentTypeId", "IMAGE");
        productContentCtx.put("fromDate", UtilDateTime.nowTimestamp());
        productContentCtx.put("userLogin", userLogin);
        productContentCtx.put("contentId", contentId);
        productContentCtx.put("statusId", "IM_PENDING");
        try {
            Map<String, Object> serviceResult = dispatcher.runSync("createProductContent", productContentCtx);
            if (ServiceUtil.isError(serviceResult)) {
                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));
            }
        } catch (GenericServiceException e) {
            Debug.logError(e, module);
            result = ServiceUtil.returnError(e.getMessage());
            result.putAll(context);
        }
        Map<String, Object> contentApprovalCtx = new HashMap<>();
        contentApprovalCtx.put("contentId", contentId);
        contentApprovalCtx.put("userLogin", userLogin);
        try {
            Map<String, Object> serviceResult = dispatcher.runSync("createImageContentApproval", contentApprovalCtx);
            if (ServiceUtil.isError(serviceResult)) {
                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));
            }
        } catch (GenericServiceException e) {
            Debug.logError(e, module);
            result = ServiceUtil.returnError(e.getMessage());
            result.putAll(context);
        }
    } else {
        String errMsg = UtilProperties.getMessage(resourceError, "ProductPleaseSelectImage", locale);
        Debug.logFatal(errMsg, module);
        result = ServiceUtil.returnError(errMsg);
        result.putAll(context);
    }
    String successMsg = UtilProperties.getMessage(resource, "ProductFrameImageSuccessfully", locale);
    result = ServiceUtil.returnSuccess(successMsg);
    return result;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) HashMap(java.util.HashMap) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) RenderedImage(java.awt.image.RenderedImage) BufferedImage(java.awt.image.BufferedImage) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 65 with GenericEntityException

use of org.apache.ofbiz.entity.GenericEntityException in project ofbiz-framework by apache.

the class ImageManagementServices method createContentAndDataResource.

public static Map<String, Object> createContentAndDataResource(DispatchContext dctx, GenericValue userLogin, String filenameToUse, String imageUrl, String contentId, String fileContentType) {
    Map<String, Object> result = new HashMap<>();
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Delegator delegator = dctx.getDelegator();
    Map<String, Object> dataResourceCtx = new HashMap<>();
    dataResourceCtx.put("objectInfo", imageUrl);
    dataResourceCtx.put("dataResourceName", filenameToUse);
    dataResourceCtx.put("userLogin", userLogin);
    dataResourceCtx.put("dataResourceTypeId", "IMAGE_OBJECT");
    dataResourceCtx.put("mimeTypeId", fileContentType);
    dataResourceCtx.put("isPublic", "Y");
    Map<String, Object> dataResourceResult;
    try {
        dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx);
        if (ServiceUtil.isError(dataResourceResult)) {
            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(dataResourceResult));
        }
    } catch (GenericServiceException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    String dataResourceId = (String) dataResourceResult.get("dataResourceId");
    result.put("dataResourceFrameId", dataResourceId);
    result.put("dataResourceId", dataResourceId);
    Map<String, Object> contentUp = new HashMap<>();
    contentUp.put("contentId", contentId);
    contentUp.put("dataResourceId", dataResourceResult.get("dataResourceId"));
    contentUp.put("contentName", filenameToUse);
    contentUp.put("userLogin", userLogin);
    try {
        Map<String, Object> serviceResult = dispatcher.runSync("updateContent", contentUp);
        if (ServiceUtil.isError(serviceResult)) {
            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));
        }
    } catch (GenericServiceException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    GenericValue content = null;
    try {
        content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne();
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    if (content != null) {
        GenericValue dataResource = null;
        try {
            dataResource = content.getRelatedOne("DataResource", false);
        } catch (GenericEntityException e) {
            Debug.logError(e, module);
            return ServiceUtil.returnError(e.getMessage());
        }
        if (dataResource != null) {
            dataResourceCtx.put("dataResourceId", dataResource.getString("dataResourceId"));
            try {
                Map<String, Object> serviceResult = dispatcher.runSync("updateDataResource", dataResourceCtx);
                if (ServiceUtil.isError(serviceResult)) {
                    return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));
                }
            } catch (GenericServiceException e) {
                Debug.logError(e, module);
                return ServiceUtil.returnError(e.getMessage());
            }
        }
    }
    return result;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) Delegator(org.apache.ofbiz.entity.Delegator) HashMap(java.util.HashMap) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException)

Aggregations

GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)913 GenericValue (org.apache.ofbiz.entity.GenericValue)847 Delegator (org.apache.ofbiz.entity.Delegator)599 Locale (java.util.Locale)384 HashMap (java.util.HashMap)336 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)270 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)259 LinkedList (java.util.LinkedList)231 BigDecimal (java.math.BigDecimal)213 Timestamp (java.sql.Timestamp)171 Map (java.util.Map)109 GeneralException (org.apache.ofbiz.base.util.GeneralException)95 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)78 IOException (java.io.IOException)75 EntityListIterator (org.apache.ofbiz.entity.util.EntityListIterator)57 Security (org.apache.ofbiz.security.Security)54 ArrayList (java.util.ArrayList)48 EntityExpr (org.apache.ofbiz.entity.condition.EntityExpr)47 GenericTransactionException (org.apache.ofbiz.entity.transaction.GenericTransactionException)39 LinkedHashMap (java.util.LinkedHashMap)37