use of net.fortuna.ical4j.model.Component in project opencast by opencast.
the class SchedulerServiceImplTest method checkIcalFeed.
private void checkIcalFeed(Map<String, String> caProps, String title) throws Exception {
final String cs = schedSvc.getCalendar(Opt.<String>none(), Opt.<String>none(), Opt.<Date>none());
final Calendar cal = new CalendarBuilder().build(new StringReader(cs));
assertEquals("number of entries", 1, cal.getComponents().size());
for (Object co : cal.getComponents()) {
final Component c = (Component) co;
assertEquals("SUMMARY property should contain the DC title", title, c.getProperty(Property.SUMMARY).getValue());
final Monadics.ListMonadic<Property> attachments = mlist(c.getProperties(Property.ATTACH)).map(Misc.<Object, Property>cast());
// episode dublin core
final List<DublinCoreCatalog> dcsIcal = attachments.filter(byParamNameAndValue("X-APPLE-FILENAME", "episode.xml")).map(parseDc.o(decodeBase64).o(getValue)).value();
assertEquals("number of episode DCs", 1, dcsIcal.size());
assertEquals("dcterms:title", title, dcsIcal.get(0).getFirst(PROPERTY_TITLE));
// capture agent properties
final List<Properties> caPropsIcal = attachments.filter(byParamNameAndValue("X-APPLE-FILENAME", "org.opencastproject.capture.agent.properties")).map(parseProperties.o(decodeBase64).o(getValue)).value();
assertEquals("number of CA property sets", 1, caPropsIcal.size());
assertTrue("CA properties", eqObj(caProps, caPropsIcal.get(0)));
}
}
use of net.fortuna.ical4j.model.Component in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method makeOldTimeZonesMap.
private static Map<String, VTimeZone> makeOldTimeZonesMap(Params params) {
Map<String, VTimeZone> oldTimeZones = Maps.newHashMap();
if (null != params.oldTimezonesFileName) {
try (FileInputStream fin = new FileInputStream(params.oldTimezonesFileName)) {
CalendarBuilder builder = new CalendarBuilder();
net.fortuna.ical4j.model.Calendar calendar = builder.build(fin, "UTF-8");
for (Iterator i = calendar.getComponents().iterator(); i.hasNext(); ) {
Component component = (Component) i.next();
if (Component.VTIMEZONE.equals(component.getName())) {
VTimeZone vtz = (VTimeZone) component;
Property tzprop = vtz.getProperties().getProperty(Property.TZID);
if (null != tzprop) {
oldTimeZones.put(tzprop.getValue(), vtz);
}
}
}
} catch (IOException | ParserException e) {
System.err.println("Problem loading old timezones.ics - ignoring it. " + e.getMessage());
}
}
return oldTimeZones;
}
use of net.fortuna.ical4j.model.Component in project zm-mailbox by Zimbra.
the class TimeZoneDefinition method addVtimezone.
public void addVtimezone(ContentHandler icalOutput) throws ParserException, URISyntaxException, IOException, ParseException {
if (getTimezoneName() == null) {
return;
}
if (effectiveRule == null) {
return;
}
getTimeZone();
if (theZone == null) {
return;
}
VTimeZone vtz = theZone.getVTimeZone();
icalOutput.startComponent(Component.VTIMEZONE);
for (Object obj : vtz.getProperties()) {
if (obj instanceof Property) {
Property currProp = (Property) obj;
IcalUtil.addProperty(icalOutput, currProp);
}
}
for (Object obj : vtz.getObservances()) {
if (obj instanceof Component) {
Component currComp = (Component) obj;
icalOutput.startComponent(currComp.getName());
for (Object propObj : currComp.getProperties()) {
if (propObj instanceof Property) {
Property obsProp = (Property) propObj;
IcalUtil.addProperty(icalOutput, obsProp);
}
}
icalOutput.endComponent(currComp.getName());
}
}
icalOutput.endComponent(Component.VTIMEZONE);
if (true) {
return;
}
}
use of net.fortuna.ical4j.model.Component in project ofbiz-framework by apache.
the class ICalConverter method toCalendarComponent.
protected static ResponseProperties toCalendarComponent(ComponentList components, GenericValue workEffort, Map<String, Object> context) throws GenericEntityException {
Delegator delegator = workEffort.getDelegator();
String workEffortId = workEffort.getString("workEffortId");
String workEffortUid = workEffort.getString("universalId");
String workEffortTypeId = workEffort.getString("workEffortTypeId");
GenericValue typeValue = EntityQuery.use(delegator).from("WorkEffortType").where("workEffortTypeId", workEffortTypeId).cache().queryOne();
boolean isTask = false;
boolean newComponent = true;
ComponentList resultList = null;
ComponentList alarms = null;
Component result = null;
if ("TASK".equals(workEffortTypeId) || (typeValue != null && "TASK".equals(typeValue.get("parentTypeId")))) {
isTask = true;
resultList = components.getComponents("VTODO");
} else if ("EVENT".equals(workEffortTypeId) || (typeValue != null && "EVENT".equals(typeValue.get("parentTypeId")))) {
resultList = components.getComponents("VEVENT");
} else {
return null;
}
Iterator<Component> i = UtilGenerics.cast(resultList.iterator());
while (i.hasNext()) {
result = i.next();
Property xProperty = result.getProperty(workEffortIdXPropName);
if (xProperty != null && workEffortId.equals(xProperty.getValue())) {
newComponent = false;
break;
}
Property uid = result.getProperty(Uid.UID);
if (uid != null && uid.getValue().equals(workEffortUid)) {
newComponent = false;
break;
}
}
if (isTask) {
VToDo toDo = null;
if (newComponent) {
toDo = new VToDo();
result = toDo;
} else {
toDo = (VToDo) result;
}
alarms = toDo.getAlarms();
} else {
VEvent event = null;
if (newComponent) {
event = new VEvent();
result = event;
} else {
event = (VEvent) result;
}
alarms = event.getAlarms();
}
if (newComponent) {
components.add(result);
}
PropertyList componentProps = result.getProperties();
loadWorkEffort(componentProps, workEffort);
if (isTask) {
replaceProperty(componentProps, toCompleted(workEffort.getTimestamp("actualCompletionDate")));
replaceProperty(componentProps, toPercentComplete(workEffort.getLong("percentComplete")));
} else {
replaceProperty(componentProps, toDtEnd(workEffort.getTimestamp("estimatedCompletionDate")));
}
if (workEffort.get("estimatedCompletionDate") == null) {
replaceProperty(componentProps, toDuration(workEffort.getDouble("estimatedMilliSeconds")));
}
List<GenericValue> relatedParties = EntityQuery.use(delegator).from("WorkEffortPartyAssignView").where("workEffortId", workEffortId).cache(true).filterByDate().queryList();
if (relatedParties.size() > 0) {
loadRelatedParties(relatedParties, componentProps, context);
}
if (newComponent) {
if (UtilValidate.isNotEmpty(workEffort.getString("tempExprId"))) {
TemporalExpression tempExpr = TemporalExpressionWorker.getTemporalExpression(delegator, workEffort.getString("tempExprId"));
if (tempExpr != null) {
try {
ICalRecurConverter.convert(tempExpr, componentProps);
} catch (Exception e) {
replaceProperty(componentProps, new Description("Error while converting recurrence: " + e));
}
}
}
getAlarms(workEffort, alarms);
}
if (Debug.verboseOn()) {
try {
result.validate(true);
Debug.logVerbose("iCalendar component passes validation", module);
} catch (ValidationException e) {
Debug.logVerbose(e, "iCalendar component fails validation: ", module);
}
}
return null;
}
use of net.fortuna.ical4j.model.Component in project ofbiz-framework by apache.
the class ICalConverter method storeCalendar.
/**
* Update work efforts from an incoming iCalendar request.
* @param is
* @param context
* @throws IOException
* @throws ParserException
* @throws GenericEntityException
* @throws GenericServiceException
*/
public static ResponseProperties storeCalendar(InputStream is, Map<String, Object> context) throws IOException, ParserException, GenericEntityException, GenericServiceException {
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = null;
try {
calendar = builder.build(is);
} finally {
if (is != null) {
is.close();
}
}
if (Debug.verboseOn()) {
Debug.logVerbose("Processing calendar:\r\n" + calendar, module);
}
String workEffortId = fromXProperty(calendar.getProperties(), workEffortIdXPropName);
if (workEffortId == null) {
workEffortId = (String) context.get("workEffortId");
}
if (!workEffortId.equals(context.get("workEffortId"))) {
Debug.logWarning("Spoof attempt: received calendar workEffortId " + workEffortId + " on URL workEffortId " + context.get("workEffortId"), module);
return ICalWorker.createForbiddenResponse(null);
}
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 (context.get("userLogin") == null) {
return ICalWorker.createNotAuthorizedResponse(null);
}
if (!hasPermission(workEffortId, "UPDATE", context)) {
return ICalWorker.createForbiddenResponse(null);
}
boolean hasCreatePermission = hasPermission(workEffortId, "CREATE", context);
List<GenericValue> workEfforts = getRelatedWorkEfforts(publishProperties, context);
Set<String> validWorkEfforts = new HashSet<>();
if (UtilValidate.isNotEmpty(workEfforts)) {
// Security issue: make sure only related work efforts get updated
for (GenericValue workEffort : workEfforts) {
validWorkEfforts.add(workEffort.getString("workEffortId"));
}
}
List<Component> components = UtilGenerics.checkList(calendar.getComponents(), Component.class);
ResponseProperties responseProps = null;
for (Component component : components) {
if (Component.VEVENT.equals(component.getName()) || Component.VTODO.equals(component.getName())) {
workEffortId = fromXProperty(component.getProperties(), workEffortIdXPropName);
if (workEffortId == null) {
Property uid = component.getProperty(Uid.UID);
if (uid != null) {
GenericValue workEffort = EntityQuery.use(delegator).from("WorkEffort").where("universalId", uid.getValue()).queryFirst();
if (workEffort != null) {
workEffortId = workEffort.getString("workEffortId");
}
}
}
if (workEffortId != null) {
if (validWorkEfforts.contains(workEffortId)) {
replaceProperty(component.getProperties(), toXProperty(workEffortIdXPropName, workEffortId));
responseProps = storeWorkEffort(component, context);
} else {
Debug.logWarning("Spoof attempt: unrelated workEffortId " + workEffortId + " on URL workEffortId " + context.get("workEffortId"), module);
responseProps = ICalWorker.createForbiddenResponse(null);
}
} else if (hasCreatePermission) {
responseProps = createWorkEffort(component, context);
}
if (responseProps != null) {
return responseProps;
}
}
}
Map<String, ? extends Object> serviceMap = UtilMisc.toMap("workEffortId", context.get("workEffortId"), "icalData", calendar.toString());
GenericValue iCalData = publishProperties.getRelatedOne("WorkEffortIcalData", false);
Map<String, Object> serviceResult = null;
if (iCalData == null) {
serviceResult = invokeService("createWorkEffortICalData", serviceMap, context);
} else {
serviceResult = invokeService("updateWorkEffortICalData", serviceMap, context);
}
if (ServiceUtil.isError(serviceResult)) {
return ICalWorker.createPartialContentResponse(ServiceUtil.getErrorMessage(serviceResult));
}
return ICalWorker.createOkResponse(null);
}
Aggregations