Summary

Here is the entire listing for the façade class:

Figure 1. Façade class listing
package curam.cookbook.facade.persistence;

import curam.util.persistence.GuiceWrapper;
import curam.util.type.DateRange;

import java.util.Set;

import com.google.inject.Inject;

import curam.cookbook.SomeChild;
import curam.cookbook.SomeEntity;
import curam.cookbook.SomeEntityDAO;
import curam.cookbook.SomeParent;
import curam.cookbook.SomeParentDAO;
import curam.cookbook.facade.struct.SomeChildSummaryDetails;
import curam.cookbook.facade.struct.SomeChildSummaryDetailsList;
import curam.cookbook.facade.struct.SomeEntityDetails;
import curam.cookbook.facade.struct.SomeEntityKeyVersion;
import curam.cookbook.facade.struct.SomeEntitySummaryDetails;
import curam.cookbook.facade.struct.SomeEntitySummaryDetailsList;
import curam.cookbook.sl.entity.struct.SomeEntityDtls;
import curam.cookbook.sl.entity.struct.SomeEntityKey;
import curam.cookbook.sl.entity.struct.SomeParentKey;
import curam.util.exception.AppException;
import curam.util.exception.InformationalException;

public class MyFacade {

  @Inject
  private SomeEntityDAO someEntityDAO;

  public MyFacade() {
    GuiceWrapper.getInjector().injectMembers(this);
  }

  public SomeEntityDetails viewSomeEntityDetails(
    final SomeEntityKey key)
      throws AppException, InformationalException {

    // create an instance of the return struct
    final SomeEntityDetails someEntityDetails =
      new SomeEntityDetails();

    // retrieve the instance of the entity
    final SomeEntity someEntity =
      someEntityDAO.get(key.someEntityID);

    // map the details from the entity instance
    someEntityDetails.details.someEntityID = someEntity.getID();
    someEntityDetails.details.name = someEntity.getName();
    someEntityDetails.details.versionNo = someEntity.getVersionNo();

    final DateRange dateRange = someEntity.getDateRange();
    someEntityDetails.details.startDate = dateRange.start();
    someEntityDetails.details.endDate = dateRange.end();
    // ...more mappings

    // return to the client
    return someEntityDetails;
  }

   public SomeEntityKey createSomeEntityDetails(
    final SomeEntityDetails details)
      throws AppException, InformationalException {

    // create an instance of the return struct
    final SomeEntityKey key = new SomeEntityKey();

    // create a new entity instance
    final SomeEntity someEntity = someEntityDAO.newInstance();

    // map the details
    someEntity.setName(details.details.name);

    final DateRange dateRange =
      new DateRange(details.details.startDate,
        details.details.endDate);
    someEntity.setDateRange(dateRange);
    // ...more mappings

    // do the insert
    someEntity.insert();

    // map the key assigned
    key.someEntityID = someEntity.getID();

    // return to the client
    return key;
  }

   public void modifySomeEntityDetails(
    final SomeEntityDetails details)
      throws AppException, InformationalException {

    // retrieve the instance of the entity
    final SomeEntity someEntity = someEntityDAO
        .get(details.details.someEntityID);

    // set the fields
    setSomeEntityDetails(someEntity, details.details);

    // do the modify, passing the version number from the client
    someEntity.modify(details.details.versionNo);

  }

  /**
   * Maps client details to the setters on the service-layer API
   *
   * @param someEntity
   *          the service-layer instance of the entity
   * @param someEntityDtls
   *          the client details to map
   *
   */
  private void setSomeEntityDetails(final SomeEntity someEntity,
      final SomeEntityDtls someEntityDtls) {

    // map the details
    someEntity.setName(someEntityDtls.name);

    final DateRange dateRange = new DateRange(
    someEntityDtls.startDate,
        someEntityDtls.endDate);
    someEntity.setDateRange(dateRange);
    // ...more mappings
  }

  public void removeSomeEntityDetails(
    final SomeEntityKeyVersion key)
      throws AppException, InformationalException {

    // retrieve the instance of the entity
    final SomeEntity someEntity =
      someEntityDAO.get(key.someEntityID);

    // do the remove, passing the version number from the client
    someEntity.remove(key.versionNo);

  }

   public void cancelSomeEntityDetails(
    final SomeEntityKeyVersion key)
      throws AppException, InformationalException {

    // retrieve the instance of the entity
    final SomeEntity someEntity =
      someEntityDAO.get(key.someEntityID);

    // do the cancel, passing the version number from the client
    someEntity.cancel(key.versionNo);

  }

  public SomeEntitySummaryDetailsList listSomeEntityDetails()
      throws AppException, InformationalException {

    // create an instance of the return struct
    final SomeEntitySummaryDetailsList list =
      new SomeEntitySummaryDetailsList();

    // retrieve all the instances of the entity
    final Set<SomeEntity> someEntities = someEntityDAO.readAll();

    // map the details returned
    for (final SomeEntity someEntity : someEntities) {
      final SomeEntitySummaryDetails someEntitySummaryDetails =
        new SomeEntitySummaryDetails();
      someEntitySummaryDetails.someEntityID = someEntity.getID();
      someEntitySummaryDetails.name = someEntity.getName();

      list.details.addRef(someEntitySummaryDetails);
    }

    // return to the client
    return list;
  }

  @Inject
  private SomeParentDAO someParentDAO;

  public SomeChildSummaryDetailsList listSomeChildDetails(
      final SomeParentKey key)
      throws AppException, InformationalException {

    // create an instance of the return struct
    final SomeChildSummaryDetailsList list =
      new SomeChildSummaryDetailsList();

    // retrieve the instance of the parent entity
    final SomeParent someParent =
      someParentDAO.get(key.someParentID);

    // retrieve all the child instances of the entity for this
    // parent
    final Set<SomeChild> someChildren =
      someParent.getSomeChildren();

    // map the details returned
    for (final SomeChild someChild : someChildren) {
      final SomeChildSummaryDetails someChildSummaryDetails =
        new SomeChildSummaryDetails();
      someChildSummaryDetails.someChildID = someChild.getID();
      someChildSummaryDetails.name = someChild.getName();

      list.details.addRef(someChildSummaryDetails);
    }

    // return to the client
    return list;
  }