/**
  * Analogous to {@link List#contains(Object)}, but does not perform {@link ConcurrencyChecking
  * concurrency checking} of the OID.
  */
 public boolean containedIn(List<ObjectAdapterMemento> list) {
   // REVIEW: heavy handed, ought to be possible to just compare the OIDs
   // ignoring the concurrency checking
   final ObjectAdapter currAdapter = getObjectAdapter(ConcurrencyChecking.NO_CHECK);
   for (ObjectAdapterMemento each : list) {
     if (each == null) {
       continue;
     }
     final ObjectAdapter otherAdapter = each.getObjectAdapter(ConcurrencyChecking.NO_CHECK);
     if (currAdapter == otherAdapter) {
       return true;
     }
   }
   return false;
 }
Esempio n. 2
0
  protected void setObject(final ObjectAdapterMemento parentObjectAdapterMemento) {
    final OneToOneAssociation property = propertyMemento.getProperty();
    final ObjectAdapter associatedAdapter =
        property.get(parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK));

    setObject(associatedAdapter);
  }
Esempio n. 3
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((adapterMemento == null) ? 0 : adapterMemento.hashCode());
   return result;
 }
 @Override
 public void resetVersion(ObjectAdapterMemento oam) {
   // REVIEW: this may be redundant because recreateAdapter also guarantees the version will be
   // reset.
   final ObjectAdapter adapter = recreateAdapter(oam, ConcurrencyChecking.NO_CHECK);
   Oid oid = adapter.getOid();
   oam.persistentOidStr = oid.enString(getOidMarshaller());
 }
Esempio n. 5
0
 @Override
 public ObjectAdapterMemento getObject() {
   if (hasPending) {
     return pending;
   }
   final ObjectAdapter adapter = entityModel.getObject();
   return ObjectAdapterMemento.createOrNull(adapter);
 }
Esempio n. 6
0
  /**
   * Not Wicket API, but used by <tt>EntityPage</tt> to do eager loading when rendering after
   * post-and-redirect.
   *
   * @return
   */
  public ObjectAdapter load(ConcurrencyChecking concurrencyChecking) {
    if (adapterMemento == null) {
      return null;
    }

    final ObjectAdapter objectAdapter = adapterMemento.getObjectAdapter(concurrencyChecking);
    return objectAdapter;
  }
  /**
   * Filters all choices against a term by using their {@link
   * org.apache.isis.core.metamodel.adapter.ObjectAdapter#titleString(org.apache.isis.core.metamodel.adapter.ObjectAdapter)
   * title string}
   *
   * @param term The term entered by the user
   * @param choicesMementos The collections of choices to filter
   * @return A list of all matching choices
   */
  protected List<ObjectAdapterMemento> obtainMementos(
      String term, Collection<ObjectAdapterMemento> choicesMementos) {
    List<ObjectAdapterMemento> matches = Lists.newArrayList();
    if (Strings.isEmpty(term)) {
      matches.addAll(choicesMementos);
    } else {
      for (ObjectAdapterMemento candidate : choicesMementos) {
        ObjectAdapter objectAdapter = candidate.getObjectAdapter(ConcurrencyChecking.NO_CHECK);
        String title = objectAdapter.titleString(objectAdapter);
        if (title.toLowerCase().contains(term.toLowerCase())) {
          matches.add(candidate);
        }
      }
    }

    return matches;
  }
Esempio n. 8
0
 @Override
 public String getLongName(final ScalarModel scalarModel) {
   final ObjectAdapterMemento adapterMemento = scalarModel.getObjectAdapterMemento();
   if (adapterMemento == null) {
     // shouldn't happen
     return null;
   }
   ObjectSpecId objectSpecId = adapterMemento.getObjectSpecId();
   final String specShortName =
       SpecUtils.getSpecificationFor(objectSpecId).getShortIdentifier();
   final String parmId =
       scalarModel
           .getParameterMemento()
           .getActionParameter()
           .getIdentifier()
           .toNameIdentityString();
   return specShortName + "-" + parmId + "-" + scalarModel.getParameterMemento().getNumber();
 }
Esempio n. 9
0
 /**
  * Resets the {@link #propertyScalarModels hash} of {@link ScalarModel}s for each {@link
  * PropertyMemento property} to the value held in the underlying {@link #getObject() entity}.
  */
 public void resetPropertyModels() {
   adapterMemento.resetVersion();
   for (final PropertyMemento pm : propertyScalarModels.keySet()) {
     final ScalarModel scalarModel = propertyScalarModels.get(pm);
     final ObjectAdapter adapter = getObject();
     final ObjectAdapter associatedAdapter =
         pm.getProperty().get(adapter, InteractionInitiatedBy.USER);
     scalarModel.setObject(associatedAdapter);
   }
 }
Esempio n. 10
0
 /**
  * In order that <tt>IsisAjaxFallbackDataTable</tt> can use a <tt>ReuseIfModelsEqualStrategy</tt>
  * to preserve any concurrency exception information in original model.
  */
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   EntityModel other = (EntityModel) obj;
   if (adapterMemento == null) {
     if (other.adapterMemento != null) return false;
   } else if (!adapterMemento.equals(other.adapterMemento)) return false;
   return true;
 }
  @Override
  protected String getDisplayText(final ObjectAdapterMemento choice) {
    if (choice == null) {
      return NULL_DISPLAY_TEXT;
    }

    final ObjectAdapter objectAdapter = choice.getObjectAdapter(ConcurrencyChecking.NO_CHECK);
    final IConverter<Object> converter = findConverter(objectAdapter);
    return converter != null
        ? converter.convertToString(objectAdapter.getObject(), getLocale())
        : objectAdapter.titleString(null);
  }
Esempio n. 12
0
  /**
   * Creates a model representing an action parameter of an action of a parent object, with the
   * {@link #getObject() value of this model} to be default value (if any) of that action parameter.
   */
  public ScalarModel(
      final ObjectAdapterMemento parentObjectAdapterMemento, final ActionParameterMemento apm) {
    this.kind = Kind.PARAMETER;
    this.parentObjectAdapterMemento = parentObjectAdapterMemento;
    this.parameterMemento = apm;

    final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
    // REVIEW: is no checking ok here?
    final ObjectAdapter defaultAdapter =
        actionParameter.getDefault(
            parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.NO_CHECK));
    setObject(defaultAdapter);

    setMode(Mode.EDIT);
  }
Esempio n. 13
0
      @Override
      ObjectAdapter recreateAdapter(
          final ObjectAdapterMemento oam, ConcurrencyChecking concurrencyChecking) {
        RootOid oid = getOidMarshaller().unmarshal(oam.persistentOidStr, RootOid.class);
        try {
          final ObjectAdapter adapter = getAdapterManager().adapterFor(oid, concurrencyChecking);
          return adapter;

        } finally {
          // a side-effect of AdapterManager#adapterFor(...) is that it will update the oid
          // with the correct version, even when there is a concurrency exception
          // we copy this updated oid string into our memento so that, if we retry,
          // we will succeed second time around

          oam.persistentOidStr = oid.enString(getOidMarshaller());
        }
      }
Esempio n. 14
0
 public EntityModel(final PageParameters pageParameters) {
   this(ObjectAdapterMemento.createPersistent(rootOidFrom(pageParameters)));
   hintPageParameterSerializer.pageParametersToHints(pageParameters, getHints());
 }
 @Override
 protected Object getId(final ObjectAdapterMemento choice) {
   return choice != null ? choice.asString() : NULL_PLACEHOLDER;
 }
Esempio n. 16
0
 private ObjectAdapter getPendingAdapter() {
   final ObjectAdapterMemento memento = getObject();
   return memento != null ? memento.getObjectAdapter(ConcurrencyChecking.NO_CHECK) : null;
 }
Esempio n. 17
0
 @Override
 public void setObject(final ObjectAdapter adapter) {
   super.setObject(adapter);
   adapterMemento = ObjectAdapterMemento.createOrNull(adapter);
 }
Esempio n. 18
0
 /**
  * Overridable for submodels (eg {@link ScalarModel}) that know the type of the adapter without
  * there being one.
  */
 public ObjectSpecification getTypeOfSpecification() {
   if (adapterMemento == null) {
     return null;
   }
   return getSpecificationFor(adapterMemento.getObjectSpecId());
 }
Esempio n. 19
0
 public EntityModel(final ObjectAdapter adapter) {
   this(ObjectAdapterMemento.createOrNull(adapter));
   setObject(adapter);
 }