JournalComponent.fromCrawledBlock constructor

JournalComponent.fromCrawledBlock(
  1. CrawledBlock block
)

Implementation

factory JournalComponent.fromCrawledBlock(CrawledBlock block) {
  assert(
    block.blockName.toUpperCase() == "VJOURNAL",
    "Received invalid block: ${block.blockName}",
  );

  ClassificationProperty? classification;
  DateTimeCreatedProperty? dateTimeCreated;
  DescriptionProperty? description;
  DateTimeStartProperty? dateTimeStart;
  DateTimeStampProperty? dateTimeStamp;
  LastModifiedProperty? lastModified;
  OrganizerProperty? organizer;
  RecurrenceIdProperty? recurrenceId;
  SequenceProperty? sequence;
  StatusProperty? status;
  SummaryProperty? summary;
  UniqueIdentifierProperty? uniqueIdentifier;
  URLProperty? url;
  List<UriAttachmentProperty>? uriAttachments;
  List<BinaryAttachmentProperty>? binaryAttachments;
  List<AttendeeProperty>? attendees;
  List<CategoriesProperty>? categories;
  List<CommentProperty>? comments;
  List<ContactProperty>? contacts;
  List<ExceptionDateTimesProperty>? exceptionDateTimes;
  List<ExceptionRuleProperty>? exceptionRules;
  List<RelatedToProperty>? relatedTo;
  List<RecurrenceDateTimesProperty>? recurrenceDateTimes;
  List<RecurrenceRuleProperty>? recurrenceRules;
  List<RequestStatusProperty>? requestStatuses;

  for (var e in block.properties) {
    switch (e.name.toUpperCase()) {
      case "CLASS":
        classification = ClassificationProperty.fromCrawledProperty(e);
        break;
      case "CREATED":
        dateTimeCreated = DateTimeCreatedProperty.fromCrawledProperty(e);
        break;
      case "DESCRIPTION":
        description = DescriptionProperty.fromCrawledProperty(e);
        break;
      case "DTSTART":
        dateTimeStart = DateTimeStartProperty.fromCrawledProperty(e);
        break;
      case "LAST-MODIFIED":
        lastModified = LastModifiedProperty.fromCrawledProperty(e);
        break;
      case "ORGANIZER":
        organizer = OrganizerProperty.fromCrawledProperty(e);
        break;
      case "DTSTAMP":
        dateTimeStamp = DateTimeStampProperty.fromCrawledProperty(e);
        break;
      case "SEQUENCE":
        sequence = SequenceProperty.fromCrawledProperty(e);
        break;
      case "STATUS":
        status = StatusProperty.fromCrawledProperty(e);
        break;
      case "SUMMARY":
        summary = SummaryProperty.fromCrawledProperty(e);
        break;
      case "UID":
        uniqueIdentifier = UniqueIdentifierProperty.fromCrawledProperty(e);
        break;
      case "URL":
        url = URLProperty.fromCrawledProperty(e);
        break;
      case "RECURRENCE-ID":
        recurrenceId = RecurrenceIdProperty.fromCrawledProperty(e);
        break;
      case "ATTACH":
        {
          final isBinary = e.parameters.any(
            (element) =>
                element.name.toUpperCase() == "VALUE" &&
                ValueDataTypeParameter.fromCrawledParameter(element).type ==
                    ValueType.binary,
          );

          if (isBinary) {
            binaryAttachments ??= [];
            binaryAttachments
                .add(BinaryAttachmentProperty.fromCrawledProperty(e));
          } else {
            uriAttachments ??= [];
            uriAttachments.add(UriAttachmentProperty.fromCrawledProperty(e));
          }
          break;
        }
      case "ATTENDEE":
        attendees ??= [];
        attendees.add(AttendeeProperty.fromCrawledProperty(e));
        break;
      case "CATEGORIES":
        categories ??= [];
        categories.add(CategoriesProperty.fromCrawledProperty(e));
        break;
      case "COMMENT":
        comments ??= [];
        comments.add(CommentProperty.fromCrawledProperty(e));
        break;
      case "CONTACT":
        contacts ??= [];
        contacts.add(ContactProperty.fromCrawledProperty(e));
        break;
      case "EXDATE":
        exceptionDateTimes ??= [];
        exceptionDateTimes
            .add(ExceptionDateTimesProperty.fromCrawledProperty(e));
        break;
      case "EXRULE":
        exceptionRules ??= [];
        exceptionRules.add(ExceptionRuleProperty.fromCrawledProperty(e));
        break;
      case "REQUEST-STATUS":
        requestStatuses ??= [];
        requestStatuses.add(RequestStatusProperty.fromCrawledProperty(e));
        break;
      case "RELATED-TO":
        relatedTo ??= [];
        relatedTo.add(RelatedToProperty.fromCrawledProperty(e));
        break;
      case "RDATE":
        recurrenceDateTimes ??= [];
        recurrenceDateTimes
            .add(RecurrenceDateTimesProperty.fromCrawledProperty(e));
        break;
      case "RRULE":
        recurrenceRules ??= [];
        recurrenceRules.add(RecurrenceRuleProperty.fromCrawledProperty(e));
        break;
      default:
        // ignore: avoid_print
        print("Unknown property encountered in JournalComponent: ${e.name}");
    }
  }

  return JournalComponent(
    classification: classification,
    dateTimeCreated: dateTimeCreated,
    description: description,
    dateTimeStart: dateTimeStart,
    dateTimeStamp: dateTimeStamp,
    lastModified: lastModified,
    organizer: organizer,
    recurrenceId: recurrenceId,
    sequence: sequence,
    status: status,
    summary: summary,
    uniqueIdentifier: uniqueIdentifier,
    url: url,
    uriAttachments: uriAttachments,
    binaryAttachments: binaryAttachments,
    attendees: attendees,
    categories: categories,
    comments: comments,
    contacts: contacts,
    exceptionDateTimes: exceptionDateTimes,
    exceptionRules: exceptionRules,
    relatedTo: relatedTo,
    recurrenceDateTimes: recurrenceDateTimes,
    recurrenceRules: recurrenceRules,
    requestStatuses: requestStatuses,
  );
}