Ejemplo n.º 1
0
  @Inject
  public Export2iCalConverter(
      TimeZoneConverter timezoneConverter,
      RaplaLocale raplaLocale,
      Logger logger,
      ClientFacade facade)
      throws RaplaException {
    this.timezoneConverter = timezoneConverter;
    this.facade = facade;
    this.raplaLocale = raplaLocale;
    this.logger = logger;
    TimeZone zone = timezoneConverter.getImportExportTimeZone();

    calendar = raplaLocale.createCalendar();
    DynamicType[] dynamicTypes =
        facade.getDynamicTypes(DynamicTypeAnnotations.VALUE_CLASSIFICATION_TYPE_RESOURCE);
    for (DynamicType type : dynamicTypes) {
      if (type.getAnnotation(DynamicTypeAnnotations.KEY_LOCATION) != null) {
        hasLocationType = true;
      }
    }
    CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION, true);

    RaplaConfiguration config =
        facade
            .getSystemPreferences()
            .getEntry(Export2iCalPlugin.ICAL_CONFIG, new RaplaConfiguration());
    global_export_attendees =
        config
            .getChild(Export2iCalPlugin.EXPORT_ATTENDEES)
            .getValueAsBoolean(Export2iCalPlugin.DEFAULT_exportAttendees);
    global_export_attendees_participation_status =
        config
            .getChild(Export2iCalPlugin.EXPORT_ATTENDEES_PARTICIPATION_STATUS)
            .getValue(Export2iCalPlugin.DEFAULT_attendee_participation_status);

    try {
      exportAttendeesAttribute =
          config.getChild(Export2iCalPlugin.EXPORT_ATTENDEES_EMAIL_ATTRIBUTE).getValue();
    } catch (ConfigurationException e) {
      exportAttendeesAttribute = "";
      getLogger().info("ExportAttendeesMailAttribute is not set. So do not export as meeting");
    }
    if (zone != null) {
      final String timezoneId = zone.getID();

      try {
        TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
        timeZone = registry.getTimeZone(timezoneId);
      } catch (Exception rc) {
        final VTimeZone vTimeZone = new VTimeZone();
        timeZone = new net.fortuna.ical4j.model.TimeZone(vTimeZone);
        final int rawOffset = zone.getRawOffset();
        timeZone.setRawOffset(rawOffset);
      }
    }
  }
Ejemplo n.º 2
0
 private String getParentId() {
   if (typeId != null) return typeId;
   if (type == null) {
     throw new UnresolvableReferenceExcpetion("type and parentId are both not set");
   }
   DynamicType dynamicType = resolver.getDynamicType(type);
   if (dynamicType == null) {
     throw new UnresolvableReferenceExcpetion(type);
   }
   typeId = dynamicType.getId();
   return typeId;
 }
Ejemplo n.º 3
0
 public static boolean isTransferedToClient(DynamicType type) {
   String annotation = type.getAnnotation(DynamicTypeAnnotations.KEY_TRANSFERED_TO_CLIENT);
   if (annotation == null) {
     return true;
   }
   return !annotation.equals(DynamicTypeAnnotations.VALUE_TRANSFERED_TO_CLIENT_NEVER);
 }
Ejemplo n.º 4
0
 /** find the attribute of the given type that matches the id */
 private Attribute findAttributeById(DynamicType type, String id) {
   Attribute[] typeAttributes = type.getAttributes();
   for (int i = 0; i < typeAttributes.length; i++) {
     String key2 = typeAttributes[i].getId();
     if (key2.equals(id)) {
       return typeAttributes[i];
     }
   }
   return null;
 }
Ejemplo n.º 5
0
  public void commitChange(DynamicType type) {
    if (!hasType(type)) {
      return;
    }

    Collection<String> removedKeys = new ArrayList<String>();
    Map<Attribute, Attribute> attributeMapping = new HashMap<Attribute, Attribute>();
    for (String key : data.keySet()) {
      Attribute attribute = getType().getAttribute(key);
      Attribute attribute2 = type.getAttribute(key);
      // key now longer availabe so remove it
      if (attribute2 == null) {
        removedKeys.add(key);
      }
      if (attribute == null) {
        continue;
      }
      String attId = attribute.getId();
      Attribute newAtt = findAttributeById(type, attId);
      if (newAtt != null) {
        attributeMapping.put(attribute, newAtt);
      }
    }
    for (Attribute attribute : attributeMapping.keySet()) {
      Collection<Object> convertedValues = new ArrayList<Object>();
      Collection<?> valueCollection = getValues(attribute);
      Attribute newAttribute = attributeMapping.get(attribute);
      for (Object oldValue : valueCollection) {
        Object newValue = newAttribute.convertValue(oldValue);
        if (newValue != null) {
          convertedValues.add(newValue);
        }
      }
      setValues(newAttribute, convertedValues);
    }

    for (String key : removedKeys) {
      data.remove(key);
    }
    this.type = type.getKey();
    name = null;
  }
  public void testPreConditions() {
    this.initializeValidAllocatableCategory();

    // Check activity class
    AllocatableDetailsActivity activity = this.getActivity();
    assertNotNull(activity);

    // Check application class
    Application app = activity.getApplication();
    assertNotNull(app);
    assertEquals(RaplaMobileApplication.class, app.getClass());

    // Check list view
    View v = activity.findViewById(R.id.allocatable_details_list);
    assertNotNull(v);
    ListView listView = (ListView) v;
    assertNotNull(listView);

    // Check create new classification from allocatable dynamic type
    DynamicType dt = FixtureHelper.createDynamicTypeAllocatable();
    dt.newClassification();
  }
Ejemplo n.º 7
0
  public static void validate(DynamicType dynamicType, I18nBundle i18n) throws RaplaException {
    Assert.notNull(dynamicType);
    if (dynamicType.getName(i18n.getLocale()).length() == 0)
      throw new RaplaException(i18n.getString("error.no_name"));

    if (dynamicType.getKey().equals("")) {
      throw new RaplaException(i18n.format("error.no_key", ""));
    }
    checkKey(i18n, dynamicType.getKey());
    Attribute[] attributes = dynamicType.getAttributes();
    for (int i = 0; i < attributes.length; i++) {
      String key = attributes[i].getKey();
      if (key == null || key.trim().equals(""))
        throw new RaplaException(i18n.format("error.no_key", "(" + i + ")"));
      checkKey(i18n, key);
      for (int j = i + 1; j < attributes.length; j++) {
        if ((key.equals(attributes[j].getKey()))) {
          throw new UniqueKeyException(i18n.format("error.not_unique", key));
        }
      }
    }
  }
Ejemplo n.º 8
0
 public AllocatableListField(
     ClientFacade facade,
     RaplaResources i18n,
     RaplaLocale raplaLocale,
     Logger logger,
     DynamicType dynamicTypeConstraint)
     throws RaplaException {
   super(facade, i18n, raplaLocale, logger, true);
   this.dynamicTypeConstraint = dynamicTypeConstraint;
   ClassificationFilter filter = dynamicTypeConstraint.newClassificationFilter();
   ClassificationFilter[] filters = new ClassificationFilter[] {filter};
   Allocatable[] allocatables = getQuery().getAllocatables(filters);
   Set<Allocatable> list = new TreeSet<Allocatable>(new NamedComparator<Allocatable>(getLocale()));
   list.addAll(Arrays.asList(allocatables));
   setVector(list);
 }
Ejemplo n.º 9
0
  public void start(Component owner, CalendarModel model, DynamicType dynamicType)
      throws RaplaException {
    wizardDialog = WizardDialog.createWizard(getContext(), owner, false);
    wizardDialog.setTitle(getString("reservation_wizard.title"));
    getLogger().debug("starting wizard");
    wizardDialog.setSize(800, 565);

    Classification newClassification = dynamicType.newClassification();
    reservation = getModification().newReservation(newClassification);
    panel1.setStart(model.getSelectedDate());
    panel1.setReservation(reservation);
    panel2.setReservation(reservation);
    getUpdateModule().addModificationListener(this);
    wizardDialog.addWindowListener(new DisposingTool(this));
    wizardDialog.setDefault(2);
    wizardDialog.start(panel1);
  }
Ejemplo n.º 10
0
  public boolean needsChange(DynamicType newType) {
    if (!hasType(newType)) {
      return false;
    }
    DynamicTypeImpl type = getType();
    if (!newType.getKey().equals(type.getKey())) return true;

    for (String key : data.keySet()) {
      Attribute attribute = getType().getAttribute(key);
      if (attribute == null) {
        return true;
      }
      String attributeId = attribute.getId();
      if (type.hasAttributeChanged((DynamicTypeImpl) newType, attributeId)) return true;
    }
    return false;
  }
Ejemplo n.º 11
0
 TypeFunction(DynamicType type) {
   super("type:" + type.getKey());
   id = type.getId();
 }
Ejemplo n.º 12
0
 private boolean isInternalType(Allocatable alloc) {
   DynamicType type = alloc.getClassification().getType();
   String annotation = type.getAnnotation(DynamicTypeAnnotations.KEY_CLASSIFICATION_TYPE);
   return annotation != null
       && annotation.equals(DynamicTypeAnnotations.VALUE_CLASSIFICATION_TYPE_RAPLATYPE);
 }
Ejemplo n.º 13
0
    public void actionPerformed(ActionEvent arg0) {
      try {
        JPanel test = new JPanel();
        test.setLayout(new BorderLayout());
        JPanel content = new JPanel();
        GridLayout layout = new GridLayout();
        layout.setColumns(2);
        layout.setHgap(5);
        layout.setVgap(5);

        // content.setLayout(new TableLayout(new
        // double[][]{{TableLayout.PREFERRED,5,TableLayout.PREFERRED},{TableLayout.PREFERRED,5,TableLayout.PREFERRED,5,TableLayout.PREFERRED, 5, TableLayout.PREFERRED}}));
        content.setLayout(layout);
        test.add(new JLabel(getString("enter_name")), BorderLayout.NORTH);
        test.add(content, BorderLayout.CENTER);
        User user = getUserModule().getUser();

        Allocatable person = user.getPerson();
        JTextField inputSurname = new JTextField();
        addCopyPaste(inputSurname);
        JTextField inputFirstname = new JTextField();
        addCopyPaste(inputFirstname);
        JTextField inputTitle = new JTextField();
        addCopyPaste(inputTitle);
        // Person connected?
        if (person != null) {
          Classification classification = person.getClassification();
          DynamicType type = classification.getType();
          Map<String, JTextField> map = new LinkedHashMap<String, JTextField>();
          map.put("title", inputTitle);
          map.put("firstname", inputFirstname);
          map.put("forename", inputFirstname);
          map.put("surname", inputSurname);
          map.put("lastname", inputSurname);
          int rows = 0;
          for (Map.Entry<String, JTextField> entry : map.entrySet()) {
            String fieldName = entry.getKey();
            Attribute attribute = type.getAttribute(fieldName);
            JTextField value = entry.getValue();
            if (attribute != null && !content.isAncestorOf(value)) {
              Locale locale = getLocale();
              content.add(new JLabel(attribute.getName(locale)));
              content.add(value);
              Object value2 = classification.getValue(attribute);
              rows++;
              if (value2 != null) {
                value.setText(value2.toString());
              }
            }
          }
          layout.setRows(rows);
        } else {
          content.add(new JLabel(getString("name")));
          content.add(inputSurname);
          inputSurname.setText(user.getName());
          layout.setRows(1);
        }
        DialogUI dlg =
            DialogUI.create(
                getContext(),
                getComponent(),
                true,
                test,
                new String[] {getString("save"), getString("abort")});
        dlg.start();
        if (dlg.getSelectedIndex() == 0) {
          String title = inputTitle.getText();
          String firstname = inputFirstname.getText();
          String surname = inputSurname.getText();
          getUserModule().changeName(title, firstname, surname);

          nameLabel.setText(user.getName());
        }
      } catch (RaplaException ex) {
        showException(ex, getMainComponent());
      }
    }