Search in sources :

Example 86 with GenericValue

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

the class ICalConverter method loadRelatedParties.

protected static void loadRelatedParties(List<GenericValue> relatedParties, PropertyList componentProps, Map<String, Object> context) {
    PropertyList attendees = componentProps.getProperties("ATTENDEE");
    for (GenericValue partyValue : relatedParties) {
        if ("CAL_ORGANIZER~CAL_OWNER".contains(partyValue.getString("roleTypeId"))) {
            // RFC 2445 4.6.1, 4.6.2, and 4.6.3 ORGANIZER can appear only once
            replaceProperty(componentProps, createOrganizer(partyValue, context));
        } else {
            String partyId = partyValue.getString("partyId");
            boolean newAttendee = true;
            Attendee attendee = null;
            Iterator<Attendee> i = UtilGenerics.cast(attendees.iterator());
            while (i.hasNext()) {
                attendee = i.next();
                Parameter xParameter = attendee.getParameter(partyIdXParamName);
                if (xParameter != null && partyId.equals(xParameter.getValue())) {
                    loadPartyAssignment(attendee, partyValue, context);
                    newAttendee = false;
                    break;
                }
            }
            if (newAttendee) {
                attendee = createAttendee(partyValue, context);
                componentProps.add(attendee);
            }
        }
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) PropertyList(net.fortuna.ical4j.model.PropertyList) Parameter(net.fortuna.ical4j.model.Parameter) XParameter(net.fortuna.ical4j.model.parameter.XParameter) Attendee(net.fortuna.ical4j.model.property.Attendee)

Example 87 with GenericValue

use of org.apache.ofbiz.entity.GenericValue 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 88 with GenericValue

use of org.apache.ofbiz.entity.GenericValue 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 89 with GenericValue

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

the class ICalConverter method getICalendar.

/**
 * Returns a calendar derived from a Work Effort calendar publish point.
 * @param workEffortId ID of a work effort with <code>workEffortTypeId</code> equal to
 * <code>PUBLISH_PROPS</code>.
 * @param context The conversion context
 * @return An iCalendar as a <code>String</code>, or <code>null</code>
 * if <code>workEffortId</code> is invalid.
 * @throws GenericEntityException
 */
public static ResponseProperties getICalendar(String workEffortId, Map<String, Object> context) throws GenericEntityException {
    Delegator delegator = (Delegator) context.get("delegator");
    GenericValue publishProperties = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortId).queryOne();
    if (!isCalendarPublished(publishProperties)) {
        Debug.logInfo("WorkEffort calendar is not published: " + workEffortId, module);
        return ICalWorker.createNotFoundResponse(null);
    }
    if (!"WES_PUBLIC".equals(publishProperties.get("scopeEnumId"))) {
        if (context.get("userLogin") == null) {
            return ICalWorker.createNotAuthorizedResponse(null);
        }
        if (!hasPermission(workEffortId, "VIEW", context)) {
            return ICalWorker.createForbiddenResponse(null);
        }
    }
    Calendar calendar = makeCalendar(publishProperties, context);
    ComponentList components = calendar.getComponents();
    List<GenericValue> workEfforts = getRelatedWorkEfforts(publishProperties, context);
    if (workEfforts != null) {
        for (GenericValue workEffort : workEfforts) {
            ResponseProperties responseProps = toCalendarComponent(components, workEffort, context);
            if (responseProps != null) {
                return responseProps;
            }
        }
    }
    if (Debug.verboseOn()) {
        try {
            calendar.validate(true);
            Debug.logVerbose("iCalendar passes validation", module);
        } catch (ValidationException e) {
            if (Debug.verboseOn())
                Debug.logVerbose("iCalendar fails validation: " + e, module);
        }
    }
    return ICalWorker.createOkResponse(calendar.toString());
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) ValidationException(net.fortuna.ical4j.model.ValidationException) Delegator(org.apache.ofbiz.entity.Delegator) ResponseProperties(org.apache.ofbiz.workeffort.workeffort.ICalWorker.ResponseProperties) Calendar(net.fortuna.ical4j.model.Calendar) ComponentList(net.fortuna.ical4j.model.ComponentList)

Example 90 with GenericValue

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

the class ICalConverter method storeWorkEffort.

protected static ResponseProperties storeWorkEffort(Component component, Map<String, Object> context) throws GenericEntityException {
    PropertyList propertyList = component.getProperties();
    String workEffortId = fromXProperty(propertyList, workEffortIdXPropName);
    Delegator delegator = (Delegator) context.get("delegator");
    GenericValue workEffort = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortId).queryOne();
    if (workEffort == null) {
        return ICalWorker.createNotFoundResponse(null);
    }
    if (!hasPermission(workEffortId, "UPDATE", context)) {
        return null;
    }
    Map<String, Object> serviceMap = new HashMap<>();
    serviceMap.put("workEffortId", workEffortId);
    setWorkEffortServiceMap(component, serviceMap);
    invokeService("updateWorkEffort", serviceMap, context);
    return storePartyAssignments(workEffortId, component, context);
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) PropertyList(net.fortuna.ical4j.model.PropertyList) Delegator(org.apache.ofbiz.entity.Delegator) HashMap(java.util.HashMap)

Aggregations

GenericValue (org.apache.ofbiz.entity.GenericValue)1422 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)871 Delegator (org.apache.ofbiz.entity.Delegator)721 Locale (java.util.Locale)505 HashMap (java.util.HashMap)463 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)370 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)356 BigDecimal (java.math.BigDecimal)338 LinkedList (java.util.LinkedList)312 Timestamp (java.sql.Timestamp)202 GeneralException (org.apache.ofbiz.base.util.GeneralException)168 Map (java.util.Map)155 IOException (java.io.IOException)116 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)97 HttpSession (javax.servlet.http.HttpSession)89 ArrayList (java.util.ArrayList)69 Security (org.apache.ofbiz.security.Security)69 EntityListIterator (org.apache.ofbiz.entity.util.EntityListIterator)59 List (java.util.List)56 EntityExpr (org.apache.ofbiz.entity.condition.EntityExpr)52