Example #1
0
/** A condition that can be used by GSON to build a JSON document representation. */
public final class RestVdbMask extends RestBasicEntity {

  /** Label used to describe name */
  public static final String NAME_LABEL =
      KomodoService.encode(VdbLexicon.DataRole.Permission.Mask.MASK);

  /** Label used to describe order */
  public static final String ORDER_LABEL =
      KomodoService.encode(VdbLexicon.DataRole.Permission.Mask.ORDER);

  /** An empty array of masks. */
  public static final RestVdbMask[] NO_MASKS = new RestVdbMask[0];

  /** Constructor for use <strong>only</strong> when deserializing. */
  public RestVdbMask() {
    // nothing to do
  }

  /**
   * Constructor for use when serializing.
   *
   * @param baseUri the base uri of the REST request
   * @param mask the mask
   * @param uow the transaction
   * @throws KException if error occurs
   */
  public RestVdbMask(URI baseUri, Mask mask, UnitOfWork uow) throws KException {
    super(baseUri, mask, uow);

    setName(mask.getName(uow));
    setOrder(mask.getOrder(uow));

    Permission permission = ancestor(mask, Permission.class, uow);
    ArgCheck.isNotNull(permission);
    String permName = permission.getName(uow);

    DataRole dataRole = ancestor(permission, DataRole.class, uow);
    ArgCheck.isNotNull(dataRole);
    String dataRoleName = dataRole.getName(uow);

    Vdb vdb = ancestor(dataRole, Vdb.class, uow);
    ArgCheck.isNotNull(vdb);
    String vdbName = vdb.getName(uow);

    Properties settings = getUriBuilder().createSettings(SettingNames.VDB_NAME, vdbName);
    getUriBuilder().addSetting(settings, SettingNames.DATA_ROLE_ID, dataRoleName);
    getUriBuilder().addSetting(settings, SettingNames.PERMISSION_ID, permName);
    getUriBuilder()
        .addSetting(settings, SettingNames.PERMISSION_CHILD_TYPE, LinkType.MASKS.uriName());
    getUriBuilder().addSetting(settings, SettingNames.PERMISSION_CHILD_ID, getId());

    addLink(
        new RestLink(
            LinkType.SELF, getUriBuilder().buildVdbPermissionChildUri(LinkType.SELF, settings)));
    addLink(
        new RestLink(
            LinkType.PARENT,
            getUriBuilder().buildVdbPermissionChildUri(LinkType.PARENT, settings)));
  }

  /** @return the name (can be empty) */
  public String getName() {
    Object value = tuples.get(NAME_LABEL);
    return value != null ? value.toString() : null;
  }

  /** @param newName the new mask name (can be empty) */
  public void setName(final String newName) {
    tuples.put(NAME_LABEL, newName);
  }

  /** @return the order */
  public String getOrder() {
    Object value = tuples.get(ORDER_LABEL);
    return value != null ? value.toString() : null;
  }

  /** @param order the order to set */
  public void setOrder(String order) {
    tuples.put(ORDER_LABEL, order);
  }
}
Example #2
0
/** A VDB model source that can be used by GSON to build a JSON model source representation. */
public final class RestVdbModelSource extends RestBasicEntity {

  /** Label used to describe jndi name */
  public static final String JNDI_NAME_LABEL = KomodoService.encode(VdbLexicon.Source.JNDI_NAME);

  /** Label used to describe translator */
  public static final String TRANSLATOR_LABEL = KomodoService.encode(VdbLexicon.Source.TRANSLATOR);

  /** Constructor for use when deserializing */
  public RestVdbModelSource() {
    super();
  }

  /**
   * Constructor for use when serializing.
   *
   * @param baseUri the base uri of the REST request
   * @param source the source
   * @param uow the transaction
   * @throws KException if error occurs
   */
  public RestVdbModelSource(URI baseUri, ModelSource source, UnitOfWork uow) throws KException {
    super(baseUri, source, uow);

    setJndiName(source.getJndiName(uow));
    String translatorName = source.getTranslatorName(uow);
    setTranslator(translatorName);

    Model model = ancestor(source, Model.class, uow);
    ArgCheck.isNotNull(model);
    String modelName = model.getName(uow);

    Vdb vdb = ancestor(model, Vdb.class, uow);
    ArgCheck.isNotNull(vdb);
    String vdbName = vdb.getName(uow);

    Properties settings = getUriBuilder().createSettings(SettingNames.VDB_NAME, vdbName);
    getUriBuilder().addSetting(settings, SettingNames.MODEL_NAME, modelName);
    getUriBuilder().addSetting(settings, SettingNames.SOURCE_NAME, getId());

    addLink(
        new RestLink(
            LinkType.SELF, getUriBuilder().buildVdbModelSourceUri(LinkType.SELF, settings)));
    addLink(
        new RestLink(
            LinkType.PARENT, getUriBuilder().buildVdbModelSourceUri(LinkType.PARENT, settings)));

    Translator[] translators = vdb.getTranslators(uow, translatorName);
    if (translators != null && translators.length == 1) {
      getUriBuilder().addSetting(settings, SettingNames.TRANSLATOR_NAME, translatorName);
      addLink(
          new RestLink(
              LinkType.REFERENCE,
              getUriBuilder().buildVdbModelSourceUri(LinkType.REFERENCE, settings)));
    }
  }

  /** @return the jndiName */
  public String getJndiName() {
    Object jndi = tuples.get(JNDI_NAME_LABEL);
    return jndi != null ? jndi.toString() : null;
  }

  /** @param jndiName the jndiName to set */
  public void setJndiName(String jndiName) {
    tuples.put(JNDI_NAME_LABEL, jndiName);
  }

  /** @return the translator */
  public String getTranslator() {
    Object translator = tuples.get(TRANSLATOR_LABEL);
    return translator != null ? translator.toString() : null;
  }

  /** @param translator the translator to set */
  public void setTranslator(String translator) {
    tuples.put(TRANSLATOR_LABEL, translator);
  }
}