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);
}
}
}
}
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;
}
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;
}
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());
}
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);
}
Aggregations