@Override
  protected List<DataSourceField> addDataSourceFields() {
    List<DataSourceField> fields = super.addDataSourceFields();

    DataSourceField idDataField = new DataSourceIntegerField("id", MSG.common_title_id(), 50);
    idDataField.setPrimaryKey(true);
    idDataField.setCanEdit(false);
    fields.add(idDataField);

    DataSourceTextField nameDataField =
        new DataSourceTextField(NAME.propertyName(), NAME.title(), 200);
    nameDataField.setCanEdit(false);
    fields.add(nameDataField);

    DataSourceTextField descriptionDataField =
        new DataSourceTextField(DESCRIPTION.propertyName(), DESCRIPTION.title());
    descriptionDataField.setCanEdit(false);
    fields.add(descriptionDataField);

    DataSourceTextField typeNameDataField =
        new DataSourceTextField(TYPE.propertyName(), TYPE.title());
    fields.add(typeNameDataField);

    DataSourceTextField pluginNameDataField =
        new DataSourceTextField(PLUGIN.propertyName(), PLUGIN.title());
    fields.add(pluginNameDataField);

    DataSourceTextField categoryDataField =
        new DataSourceTextField(CATEGORY.propertyName(), CATEGORY.title());
    fields.add(categoryDataField);

    return fields;
  }
Esempio n. 2
0
 @Override
 @SideOnly(Side.CLIENT)
 public void registerIcons(IIconRegister iconRegister) {
   for (TYPE type : TYPE.VALUES) {
     type.registerIcon(iconRegister);
   }
 }
 @Override
 public String randomValueAsString(Field<TYPE> field) {
   TYPE randomValue = randomValue(field);
   String stringValue = randomValue.toString();
   if (field.getPadding() != null) {
     long maxLength = field.getMaxLength() != 0 ? field.getMaxLength() : field.getFixedLength();
     stringValue = paddedRandomValue(field.getPadding(), randomValue, maxLength);
   }
   return stringValue;
 }
Esempio n. 4
0
 /**
  * Creates the given item.
  *
  * @param database
  * @param table table name
  * @param item item model
  * @return returns true on success.
  */
 public boolean createNew(TYPE item) {
   item.clearValue(AbstractModel.ID_PROPERTY);
   long newRow =
       database.insert(table.name, AbstractModel.ID_PROPERTY.name, item.getMergedValues());
   boolean result = newRow >= 0;
   if (result) {
     item.setId(newRow);
     onModelUpdated(item);
     item.markSaved();
   }
   return result;
 }
Esempio n. 5
0
  /**
   * Save the given object to the database. Creates a new object if model id property has not been
   * set
   *
   * @return true on success.
   */
  public boolean persist(TYPE item) {
    if (item.getId() == AbstractModel.NO_ID) {
      return createNew(item);
    } else {
      ContentValues values = item.getSetValues();

      if (values.size() == 0) // nothing changed
      return true;

      return saveExisting(item);
    }
  }
Esempio n. 6
0
 /** {@inheritDoc} */
 @Override
 public TYPE createFromParcel(Parcel source) {
   TYPE model;
   try {
     model = cls.newInstance();
   } catch (IllegalAccessException | InstantiationException e) {
     throw new RuntimeException(e);
   }
   model.setValues = source.readParcelable(ContentValues.class.getClassLoader());
   model.values = source.readParcelable(ContentValues.class.getClassLoader());
   return model;
 }
    @Override
    protected Void doInBackground(Void... voids) {

      if (TYPE.equalsIgnoreCase("ALERT") || TYPE.equalsIgnoreCase("ALERTS")) {
        fetchALertData();
      } else if (TYPE.equalsIgnoreCase("HOMEWORK")) {
        fetchHomeWorkData();
      } else {
        fetchNoticeData(TYPE);
      }

      return null;
    }
Esempio n. 8
0
 /**
  * Saves the given item. Will not create a new item!
  *
  * @param database
  * @param table table name
  * @param item item model
  * @return returns true on success.
  */
 public boolean saveExisting(TYPE item) {
   ContentValues values = item.getSetValues();
   if (values == null || values.size() == 0) // nothing changed
   return true;
   boolean result =
       database.update(
               table.name, values, AbstractModel.ID_PROPERTY.eq(item.getId()).toString(), null)
           > 0;
   if (result) {
     onModelUpdated(item);
     item.markSaved();
   }
   return result;
 }
Esempio n. 9
0
 @Override
 public String asText() {
   switch (type) {
     case ADDED:
       return type.name().toCharArray()[0]
           + "\t"
           + TextValueSerializer.asString(Optional.fromNullable((Object) newGeometry.orNull()));
     case REMOVED:
       return type.name().toCharArray()[0]
           + "\t"
           + TextValueSerializer.asString(Optional.fromNullable((Object) oldGeometry.orNull()));
     case MODIFIED:
     default:
       return type.name().toCharArray()[0] + "\t" + diff.asText();
   }
 }
  @Override
  public ListGridRecord copyValues(ResourceGroupComposite from) {
    ListGridRecord record = new ListGridRecord();
    record.setAttribute("group", from);
    record.setAttribute("id", from.getResourceGroup().getId());
    record.setAttribute(NAME.propertyName(), from.getResourceGroup().getName());
    record.setAttribute(DESCRIPTION.propertyName(), from.getResourceGroup().getDescription());
    record.setAttribute(CATEGORY.propertyName(), from.getResourceGroup().getGroupCategory().name());

    record.setAttribute("explicitCount", String.valueOf(from.getExplicitCount()));
    record.setAttribute("explicitDown", String.valueOf(from.getExplicitDown()));
    record.setAttribute("explicitDisabled", String.valueOf(from.getExplicitDisabled()));
    record.setAttribute("implicitCount", String.valueOf(from.getImplicitCount()));
    record.setAttribute("implicitDown", String.valueOf(from.getImplicitDown()));
    record.setAttribute("implicitDisabled", String.valueOf(from.getImplicitDisabled()));

    record.setAttribute(AVAIL_CHILDREN.propertyName(), getExplicitFormatted(from));
    record.setAttribute(AVAIL_DESCENDANTS.propertyName(), getImplicitFormatted(from));

    if (from.getResourceGroup().getResourceType() != null) {
      record.setAttribute("resourceType", from.getResourceGroup().getResourceType());
      record.setAttribute(TYPE.propertyName(), from.getResourceGroup().getResourceType().getName());
      record.setAttribute(
          PLUGIN.propertyName(), from.getResourceGroup().getResourceType().getPlugin());
    }

    return record;
  }
Esempio n. 11
0
 public <TYPE extends BaseMessage> TYPE getReply() {
   Class msgClass = this.getClass();
   while (!msgClass.getSimpleName().endsWith("Type")) {
     msgClass = msgClass.getSuperclass();
   }
   TYPE reply = null;
   String replyType = msgClass.getName().replaceAll("Type", "") + "ResponseType";
   try {
     Class responseClass = ClassLoader.getSystemClassLoader().loadClass(replyType);
     reply = (TYPE) responseClass.newInstance();
     reply.correlationId = this.correlationId;
   } catch (Exception e) {
     Logger.getLogger(BaseMessage.class).debug(e, e);
     throw new TypeNotPresentException(this.correlationId, e);
   }
   return reply;
 }
Esempio n. 12
0
  // =============================================================
  //  PUBLIC METHODS
  //  ============================================================
  public String getString() {
    StringBuilder builder = new StringBuilder("\n[" + mType.name() + "]");

    if (!TextUtils.isEmpty(getAction())) builder.append("\nAction:[" + getAction() + "]");
    if (!TextUtils.isEmpty(getPointer())) builder.append("\nPointer:[" + getPointer() + "]");
    for (int i = 0; i < mAttribute.size(); i++)
      if (!TextUtils.isEmpty(mAttribute.get(i).getString()))
        builder.append("\nAttr:[" + (mAttribute.get(i).getString()) + "]");

    return builder.toString();
  }
  /**
   * This method is used to apply padding to a random value to make it the required length
   *
   * @param padding the value to be padded
   * @param value the generated random value
   * @param maxLength the maximum length of the random value
   * @return the padded random value as String
   */
  private String paddedRandomValue(String padding, TYPE value, long maxLength) {
    long paddingLength = maxLength - value.toString().length();
    String formattedValue = value.toString();
    if (paddingLength <= 0) {
      return formattedValue;
    }

    StringBuilder valueWithPadding = new StringBuilder(padding);
    while (valueWithPadding.length() < paddingLength) {
      valueWithPadding.append(padding);
    }

    valueWithPadding.append(value.toString());
    if (valueWithPadding.length() > maxLength) {
      formattedValue = valueWithPadding.substring(0, (int) maxLength);
    } else {
      formattedValue = valueWithPadding.toString();
    }
    return formattedValue;
  }
Esempio n. 14
0
  @Override
  public void setProperties(LibProperties properties) {
    type = TYPE.valueOf(properties.getString(LibProperties.COLOR_HISTOGRAMS_TYPE));
    binX = properties.getInteger(LibProperties.COLOR_HISTOGRAMS_BINS_X);
    binY = properties.getInteger(LibProperties.COLOR_HISTOGRAMS_BINS_Y);
    binZ = properties.getInteger(LibProperties.COLOR_HISTOGRAMS_BINS_Z);

    checkNotNull(type, "type must not be null");
    checkArgument(binX > 0, "bin x must be >0 but was " + binX);
    checkArgument(binY > 0, "bin y must be >0 but was " + binY);
    checkArgument(binZ > 0, "bin z must be >0 but was " + binZ);
  }
Esempio n. 15
0
  /**
   * Check whether the user has changed this property value and it should be stored for saving in
   * the database
   */
  protected synchronized <TYPE> boolean shouldSaveValue(Property<TYPE> property, TYPE newValue) {

    // we've already decided to save it, so overwrite old value
    if (setValues.containsKey(property.getColumnName())) {
      return true;
    }

    // values contains this key, we should check it out
    if (values != null && values.containsKey(property.getColumnName())) {
      TYPE value = getValue(property);
      if (value == null) {
        if (newValue == null) {
          return false;
        }
      } else if (value.equals(newValue)) {
        return false;
      }
    }

    // otherwise, good to save
    return true;
  }
  /**
   * Constructs a new {@code EnumParam}, initialized to the default value. Limit the set of options
   * with the supplied {@code EnumSet}.
   *
   * @param name of the {@code Param} (max 72 chars)
   * @param info {@code String} for use in tooltips; a {@code null} value will be set to an empty
   *     {@code String} (max 256 chars)
   * @param defaultValue of the {@code Param}
   * @param options a subset of the option type
   * @throws IllegalArgumentException if {@code name} is an empty string, {@code options} is empty,
   *     or the {@code defaultValue} is not included in {@code options}
   */
  DefaultEnumParam(String name, String info, E defaultValue, Set<E> options) {
    super(name, info, defaultValue);
    checkNotNull(options);
    checkArgument(!options.isEmpty(), "Options is empty");
    checkArgument(options.contains(defaultValue), "Default missing from options");
    this.options = Sets.immutableEnumSet(options);

    // init state
    state.addProperty(TYPE.toString(), ENUM.toString());
    JsonArray stateOptions = new JsonArray();
    for (E option : options) {
      stateOptions.add(new JsonPrimitive(option.name()));
    }
    state.add(OPTIONS.toString(), stateOptions);
  }
  /**
   * Helper that reads entries from legacy database and row-by-row creates new models and saves
   * them.
   *
   * @param context
   * @param legacyTable
   * @param propertyMap
   * @param model
   * @param dao
   */
  @SuppressWarnings("nls")
  private static final <TYPE extends AbstractModel> void upgradeTable(
      Context context,
      String legacyTable,
      HashMap<String, Property<?>> propertyMap,
      TYPE model,
      DatabaseDao<TYPE> dao) {

    if (!checkIfDatabaseExists(context, legacyTable)) return;

    SQLiteDatabase upgradeDb =
        new Astrid2UpgradeHelper(context, legacyTable, null, 1).getReadableDatabase();

    Cursor cursor = upgradeDb.rawQuery("SELECT * FROM " + legacyTable, null);
    UpgradeVisitorContainer<TYPE> container = new UpgradeVisitorContainer<TYPE>();
    container.cursor = cursor;
    container.model = model;
    ColumnUpgradeVisitor visitor = new ColumnUpgradeVisitor();
    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
      model.clear();
      for (Entry<String, Property<?>> entry : propertyMap.entrySet()) {
        container.columnIndex = cursor.getColumnIndex(entry.getKey());
        entry.getValue().accept(visitor, container);
      }

      // special tweak for adding upgrade notes to tasks
      if (container.upgradeNotes != null) {
        if (container.model.getValue(Task.NOTES).length() == 0)
          container.model.setValue(Task.NOTES, container.upgradeNotes.toString());
        else {
          container.model.setValue(
              Task.NOTES, container.model.getValue(Task.NOTES) + "\n\n" + container.upgradeNotes);
        }
        container.upgradeNotes = null;
      }
      dao.createNew(container.model);
    }
    cursor.close();

    upgradeDb.close();
  }
  @Override
  public ResourceGroupComposite copyValues(Record from) {
    Integer idAttrib = from.getAttributeAsInt("id");
    String nameAttrib = from.getAttribute(NAME.propertyName());
    String descriptionAttrib = from.getAttribute(DESCRIPTION.propertyName());
    String typeNameAttrib = from.getAttribute(TYPE.propertyName());

    ResourceGroup rg = new ResourceGroup(nameAttrib);
    rg.setId(idAttrib);
    rg.setDescription(descriptionAttrib);
    if (typeNameAttrib != null) {
      ResourceType rt = new ResourceType();
      rt.setName(typeNameAttrib);
      String pluginNameAttrib = from.getAttribute(PLUGIN.propertyName());
      rt.setPlugin(pluginNameAttrib);
      rg.setResourceType(rt);
    }

    Long explicitCount = Long.valueOf(from.getAttribute("explicitCount"));
    Long explicitDown = Long.valueOf(from.getAttribute("explicitDown"));
    Long explicitUnknown = Long.valueOf(from.getAttribute("explicitUnknown"));
    Long explicitDisabled = Long.valueOf(from.getAttribute("explicitDisabled"));
    Long implicitCount = Long.valueOf(from.getAttribute("implicitCount"));
    Long implicitDown = Long.valueOf(from.getAttribute("implicitDown"));
    Long implicitUnknown = Long.valueOf(from.getAttribute("implicitUnknown"));
    Long implicitDisabled = Long.valueOf(from.getAttribute("implicitDisabled"));

    ResourceGroupComposite composite =
        new ResourceGroupComposite(
            explicitCount,
            explicitDown,
            explicitUnknown,
            explicitDisabled,
            implicitCount,
            implicitDown,
            implicitUnknown,
            implicitDisabled,
            rg);

    return composite;
  }
 public static boolean isType(String type, String format) {
   return TYPE.equals(type) && FORMAT.equals(format);
 }
 /**
  * Create the object of {@link AbstractIdentifiableEntity} type
  *
  * @param object the object to create
  * @return <code>TYPE</code> that was created
  */
 public default Optional<TYPE> create(final TYPE object) {
   this.getDAO().create(object);
   return this.getDAO().getById(object.getId());
 }
Esempio n. 21
0
 /**
  * Update all matching a clause to have the values set on template object.
  *
  * <p>Example (updates "joe" => "bob" in metadata value1): {code} Metadata item = new Metadata();
  * item.setValue(Metadata.VALUE1, "bob"); update(item, Metadata.VALUE1.eq("joe")); {code}
  *
  * @param where sql criteria
  * @param template set fields on this object in order to set them in the db.
  * @return # of updated items
  */
 public int update(Criterion where, TYPE template) {
   return database.update(table.name, template.getSetValues(), where.toString(), null);
 }
Esempio n. 22
0
 public boolean add(final TYPE e) {
   underlying.add(e.name());
   return super.add(e);
 }
Esempio n. 23
0
 protected void onModelUpdated(TYPE model) {
   TYPE modelCopy = (TYPE) model.clone();
   for (ModelUpdateListener<TYPE> listener : listeners) {
     listener.onModelUpdated(modelCopy);
   }
 }