Example #1
0
  /**
   * 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)));
    }
  }
 protected Table createTable(
     final String vdbName, final String vdbPath, final String modelName, final String tableName)
     throws Exception {
   final WorkspaceManager mgr = WorkspaceManager.getInstance(_repo);
   final Vdb vdb = mgr.createVdb(this.uow, null, vdbName, vdbPath);
   final Model model = vdb.addModel(this.uow, modelName);
   return model.addTable(this.uow, tableName);
 }
  protected Model createModel(final String vdbName, final String vdbPath, final String modelName)
      throws Exception {
    final WorkspaceManager mgr = WorkspaceManager.getInstance(_repo);
    final Vdb vdb = mgr.createVdb(this.uow, null, vdbName, vdbPath);
    final Model model = vdb.addModel(this.uow, modelName);

    assertThat(model.getPrimaryType(this.uow).getName(), is(VdbLexicon.Vdb.DECLARATIVE_MODEL));
    assertThat(model.getName(this.uow), is(modelName));
    return model;
  }
  @Before
  public void init() throws Exception {
    final Vdb vdb = createVdb();
    final Model model = createModel();
    this.parentTable = model.addTable(getTransaction(), "parentTable");

    final Model refModel = vdb.addModel(getTransaction(), "refModel");
    this.refTable = refModel.addTable(getTransaction(), "refTable");

    this.foreignKey = this.parentTable.addForeignKey(getTransaction(), NAME, this.refTable);
    commit();
  }
Example #5
0
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String viewName = requiredArgument(0, I18n.bind(ModelCommandsI18n.missingViewName));

      final Model model = getModel();
      model.addView(getTransaction(), viewName);

      result = new CommandResultImpl(I18n.bind(ModelCommandsI18n.viewAdded, viewName));
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }