Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Delete (delete templates)
Delete [message #744860] Sat, 22 October 2011 11:48 Go to next message
Bertin Kiekebosch is currently offline Bertin Kiekebosch
Messages: 306
Registered: August 2011
Senior Member
Hi,

If you edit a "Business Object" a lot of work you have to do is provided by the Scout GUI. So I use the tutorial to create and update business objects.

When I want to delete a business object I can't find a 'template'or any help from the GUI.

As an excersize I did progamm the delete myself which is pretty straight forward, although I am still asking myself did I miss something here?

Regards Bertin
Re: Delete [message #746256 is a reply to message #744860] Sun, 23 October 2011 09:48 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan Motsch
Messages: 100
Registered: March 2010
Senior Member
you wrote:
>> as an excersize I did progamm the delete myself which is pretty
do you mean the remove of a persisted entity? Can you show that code.

The main reason why scout sdk does not aut-create a "delete" business object process is because often a once created business entity is never removed but set to incative when not used anymore. This is based on the fact that audit trail, relation info and other related data must not be deleted if the entity is to be "deleted".

But java code related there is nothing that prevents - as you write - a delete operation.
Re: Delete [message #746457 is a reply to message #746256] Sun, 23 October 2011 12:56 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin Kiekebosch
Messages: 306
Registered: August 2011
Senior Member
Hi,

yes I agree that a businessObjects are rarely removed from the system.

Because in our system it is sometimes OK to remove particular objects from the database I did this exercise.
I am trying to find out how all functions of the old system we have, can be implemented with Scout in the "Scout way".


What I did to delete it:

STEP 1: Adapt the interface in the shared part

public interface IMedewerkerTypeProcessService extends IService {
  MedewerkerTypeFormData prepareCreate(MedewerkerTypeFormData formData) throws ProcessingException;
  MedewerkerTypeFormData create(MedewerkerTypeFormData formData) throws ProcessingException;
  MedewerkerTypeFormData load(MedewerkerTypeFormData formData) throws ProcessingException;
  MedewerkerTypeFormData store(MedewerkerTypeFormData formData) throws ProcessingException;
  void delete(MedewerkerTypeFormData formData) throws ProcessingException;
  void delete(Long nr) throws ProcessingException;
}


As you might notice there are two delete methods. (The last one is an improved version in a way that I only pass a nr (long ) and not a FormData object because a FormData might become large)

STEP 2: Implement the server part

public class MedewerkerTypeProcessService extends AbstractService implements IMedewerkerTypeProcessService {
...
... // removed implementation of other methods
...

  @Override
  public void delete(MedewerkerTypeFormData formData) throws ProcessingException {
    if (!ACCESS.check(new DeleteMedewerkerTypePermission())) {
      throw new VetoException(Texts.get("AuthorizationFailed"));
    }
    SQL.delete(
        "DELETE FROM EMPLOYEETYPE" +
            " WHERE ID = :medewerkerTypeNr", formData);
  }

  @Override
  public void delete(Long nr) throws ProcessingException {
    if (!ACCESS.check(new DeleteMedewerkerTypePermission())) {
      throw new VetoException(Texts.get("AuthorizationFailed"));
    }
    MedewerkerTypeFormData formData = new MedewerkerTypeFormData();
    formData.setMedewerkerTypeNr(nr);
    SQL.delete(
        "DELETE FROM EMPLOYEETYPE" +
            " WHERE ID = :medewerkerTypeNr", formData);
  }
}


There is only little difference in both implementations. Because I wanted to make use of the SQL.delete() method, in the delete(Long nr) version, I had to create a FormData object at the server side.

STEP 3: Call the method from the client side.

On the table page thats shows the records I added a menu and implemented the execAction()

    @Order(30.0)
    public class DeleteMedewerkerTypeMenu extends AbstractMenu {

      @Override
      protected String getConfiguredText() {
        return Texts.get("DeleteMedewerkerType");
      }

      @Override
      protected void execAction() throws ProcessingException {
        IMedewerkerTypeProcessService service = SERVICES.getService(IMedewerkerTypeProcessService.class);

        // with the use of formData
        //MedewerkerTypeFormData formData = new MedewerkerTypeFormData();
        //formData.setMedewerkerTypeNr(getSystemIdColumn().getSelectedValue());
        //service.delete(formData);

        // by passing the nr only
        service.delete(getSystemIdColumn().getSelectedValue());

        // when the service method is finised you can reload the page which is another 
        //server call

        //reloadPage();

        // or you can directly remove the record from the GUI with
        deleteRow(getSelectedRow());
      }
    }

Re: Delete [message #748005 is a reply to message #746457] Mon, 24 October 2011 12:21 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 765
Registered: October 2011
Senior Member
Is your solution working?

Here my example (maybe you can find one or two ideas):

Entity are here Actors.

I add in each process service a delete method:
public class ActorProcessService extends AbstractService implements IActorProcessService {
  // other methods

  public boolean delete(Long[] actorIds) throws ProcessingException {
    if (!ACCESS.check(new DeleteActorPermission())) {
      throw new VetoException(Texts.get("AuthorizationFailed"));
    }
    int nbRows = SQL.delete(
        " delete       from actor" +
            " where    actor_id = :id",
        new NVPair("id", actorIds)
        );
    return nbRows > 0;
  }
}



In the TablePage representing this entity, I have this delete menu:
    @Order(30.0)
    public class DeleteMenu extends AbstractMenu {

      @Override
      protected String getConfiguredText() {
        return ScoutTexts.get("DeleteMenu");
      }

      @Override
      protected boolean getConfiguredMultiSelectionAction() {
        return true;
      }

      @Override
      protected void execAction() throws ProcessingException {
        String[] actors = new String[getTable().getSelectedRowCount()];
        String[] firstNames = getTable().getFirstNameColumn().getSelectedValues();
        String[] lastNames = getTable().getLastNameColumn().getSelectedValues();
        for (int i = 0; i < actors.length; i++) {
          actors[i] = StringUtility.join(" ", firstNames[i], lastNames[i]);
        }

        if (MessageBox.showDeleteConfirmationMessage(Texts.get("Actor"), actors)) {
          boolean result = SERVICES.getService(IActorProcessService.class).delete(getTable().getActorIdColumn().getSelectedValues());
          if (result) {
            reloadPage();
          }
        }
      }
    }



This is very similar to what you are doing.


In forms, if you have a TableField there is another possibility: keep trace of the removed rows in the FormData... and delete them in the server. For example, imagine you have a Form to edit Films, and the entity Film has a N::M relation to Actor. In the Film Form you might want to add and remove Actors.

A solution could be to display the Actors of a Film in a TableField in the Film Form. If the user remove an Actor for the film, you keep the information of the deleted actor in the FormData, and in the modify method of your Film ProcessService, you delete the entry in your film_actor table.

I can provide you an example of this second case if you are interested.
Re: Delete [message #748561 is a reply to message #748005] Mon, 24 October 2011 19:08 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin Kiekebosch
Messages: 306
Registered: August 2011
Senior Member
Hi,

Yes my solution is working, but is meant for individual Bo's, so one at a time. I did not implement a solution for master detail (1 to N) or (M:N) yet, but I am very interested in seeing a solution for that.

regards Bertin
Re: Delete [message #750233 is a reply to message #748561] Tue, 25 October 2011 17:44 Go to previous message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 765
Registered: October 2011
Senior Member
Here the TableField in the MainBox of the Film Form:
  @Order(120.0)
  public class ActorsTableField extends AbstractTableField<ActorsTableField.Table> {
  
    @Override
    protected int getConfiguredGridH() {
      return 6;
    }
  
    @Override
    protected int getConfiguredGridW() {
      return 2;
    }
  
    @Override
    protected String getConfiguredLabel() {
      return Texts.get("Actors");
    }
  
    @Order(10.0)
    public class Table extends AbstractTable {
      //Inner-classes defining columns ActorIdColumn, FirstNameColumn, LastNameColumn
           
      @Order(10.0)
      public class AddMenu extends AbstractMenu {
  
        @Override
        protected boolean getConfiguredEmptySpaceAction() {
          return true;
        }
  
        @Override
        protected boolean getConfiguredSingleSelectionAction() {
          return false;
        }
  
        @Override
        protected String getConfiguredText() {
          return Texts.get("Add");
        }
  
        @Override
        protected void execAction() throws ProcessingException {
			//Logic to add an Actor:
			//Open a new Form where it is possible to search and to select an actor.
			//Add the actor with: 
			//    addRowsByMatrix(new Object[]{new Object[]{
            //         actorId,
            //         firstName,
            //         lastName,
            //    }});
		}
      }
  
      @Order(20.0)
      public class DeleteMenu extends AbstractMenu {
  
        @Override
        protected String getConfiguredText() {
          return Texts.get("Delete");
        }
  
        @Override
        protected boolean getConfiguredMultiSelectionAction() {
          return true;
        }
  
        @Override
        protected void execAction() throws ProcessingException {
          deleteRows(getSelectedRows());
        }
      }
    }
  }


I also have a Form Variable filmId in the form, containing the film id. Therefore the film id is contained in the formData:
formData.getFilmId()


In my process service, at the end of the create() and store() function, I call this function:
private void storeFilmActor(FilmFormData formData) throws ProcessingException {
  ActorsTable table = formData.getActorsTable();

  for (int i = 0; i < table.getRowCount(); i++) {
    switch (table.getRowState(i)) {
      case ITableHolder.STATUS_INSERTED:
        SQL.insert(
            " insert into film_actor(" +
                "    film_id, " +
                "    actor_id " +
                " ) values( " +
                "    :FilmId, " +
                "    :ActorId " +
                " ) ",
            formData,
            new NVPair("ActorId", table.getActorId(i))
            );
        break;
      case ITableHolder.STATUS_DELETED:
        SQL.delete(
            " delete       from film_actor " +
                " where    film_id = :FilmId " +
                " and      actor_id = :ActorId",
            formData,
            new NVPair("ActorId", table.getActorId(i))
            );
        break;
      case ITableHolder.STATUS_NON_CHANGED:
      case ITableHolder.STATUS_UPDATED:
      default:
        //Do nothing
        break;
    }
  }
}


By the way you also might be interested in the code to populate the ActorTableField in the load() function of my process service:
    SQL.selectInto(
    "select      actor_id, " +
        "        first_name, " +
        "        last_name " +
        " from   actor " +
        " where  1 = 1 " +
        " and    actor_id in (select actor_id from film_actor where film_id = :FilmId) " +
        " into   :ActorId, " +
        "        :FirstName," +
        "        :LastName ",
    formData,
    formData.getActorsTable()
    );

Previous Topic:Server Plugins
Next Topic:Remote Service Call / ServiceTunnel
Goto Forum:
  


Current Time: Sat Oct 25 11:19:25 GMT 2014

Powered by FUDForum. Page generated in 0.12881 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software