Пример #1
0
 @Override
 public Integer getScale(ScalarModel scalarModel) {
   final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
   final OneToOneAssociation property = propertyMemento.getProperty();
   final BigDecimalValueFacet facet = property.getFacet(BigDecimalValueFacet.class);
   return facet != null ? facet.getScale() : null;
 }
Пример #2
0
  protected void setObject(final ObjectAdapterMemento parentObjectAdapterMemento) {
    final OneToOneAssociation property = propertyMemento.getProperty();
    final ObjectAdapter associatedAdapter =
        property.get(parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK));

    setObject(associatedAdapter);
  }
Пример #3
0
 @Override
 public String parseAndValidate(
     final ScalarModel scalarModel, final String proposedPojoAsStr) {
   final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
   ParseableFacet parseableFacet = property.getFacet(ParseableFacet.class);
   if (parseableFacet == null) {
     parseableFacet = property.getSpecification().getFacet(ParseableFacet.class);
   }
   try {
     final ObjectAdapter parentAdapter =
         scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK);
     final ObjectAdapter currentValue = property.get(parentAdapter);
     Localization localization = IsisContext.getLocalization();
     final ObjectAdapter proposedAdapter =
         parseableFacet.parseTextEntry(currentValue, proposedPojoAsStr, localization);
     final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter);
     return valid.isAllowed() ? null : valid.getReason();
   } catch (final ConcurrencyException ex) {
     // disregard concurrency exceptions because will pick up at the IFormValidator level
     // rather
     // than each individual property.
     return null;
   } catch (final Exception ex) {
     return ex.getLocalizedMessage();
   }
 }
Пример #4
0
      @Override
      public int getAutoCompleteOrChoicesMinLength(ScalarModel scalarModel) {

        if (scalarModel.hasAutoComplete()) {
          final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
          final OneToOneAssociation property = propertyMemento.getProperty();
          return property.getAutoCompleteMinLength();
        } else {
          return 0;
        }
      }
Пример #5
0
 @Override
 public List<ObjectAdapter> getAutoComplete(final ScalarModel scalarModel, String searchArg) {
   final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
   final OneToOneAssociation property = propertyMemento.getProperty();
   final ObjectAdapter[] choices =
       property.getAutoComplete(
           scalarModel.parentObjectAdapterMemento.getObjectAdapter(
               ConcurrencyChecking.NO_CHECK),
           searchArg);
   return choicesAsList(choices);
 }
Пример #6
0
 @Override
 public List<ObjectAdapter> getChoices(
     final ScalarModel scalarModel, final ObjectAdapter[] argumentsIfAvailable) {
   final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
   final OneToOneAssociation property = propertyMemento.getProperty();
   final ObjectAdapter[] choices =
       property.getChoices(
           scalarModel.parentObjectAdapterMemento.getObjectAdapter(
               ConcurrencyChecking.NO_CHECK));
   return choicesAsList(choices);
 }
Пример #7
0
  /**
   * Apply changes to the underlying adapter (possibly returning a new adapter).
   *
   * @return adapter, which may be different from the original (if a {@link
   *     ViewModelFacet#isCloneable(Object) cloneable} view model, for example.
   */
  public ObjectAdapter apply() {
    ObjectAdapter adapter = getObjectAdapterMemento().getObjectAdapter(ConcurrencyChecking.CHECK);
    for (final ScalarModel scalarModel : propertyScalarModels.values()) {
      final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();

      //
      // previously there was a guard here to only apply changes provided:
      //
      // property.containsDoOpFacet(NotPersistedFacet.class) == null
      //
      // however, that logic is wrong; although a property may not be directly
      // persisted so far as JDO is concerned, it may be indirectly persisted
      // as the result of business logic in the setter.
      //
      // for example, see ExampleTaggableEntity (in isisaddons-module-tags).
      //

      //
      // on the other hand, we mustn't attempt to apply changes for disabled properties...
      // even if the property is persisted (it might be written to by an action), it is never
      // updated by
      // an edit.
      //
      // Fundamentally, then, any non-disabled property (whether persisted or not) should be updated
      // in the
      // Isis runtime.
      //

      if (property.containsDoOpFacet(DisabledFacet.class)) {
        // skip, as per comments above
        continue;
      }

      final ObjectAdapter associate = scalarModel.getObject();
      property.set(adapter, associate, InteractionInitiatedBy.USER);
    }

    final ViewModelFacet recreatableObjectFacet =
        adapter.getSpecification().getFacet(ViewModelFacet.class);
    if (recreatableObjectFacet != null) {
      final Object viewModel = adapter.getObject();
      final boolean cloneable = recreatableObjectFacet.isCloneable(viewModel);
      if (cloneable) {
        final Object newViewModel = recreatableObjectFacet.clone(viewModel);
        adapter = getAdapterManager().adapterFor(newViewModel);
      }
    }

    getObjectAdapterMemento().setAdapter(adapter);
    toViewMode();

    return adapter;
  }
Пример #8
0
 @Override
 public String validate(final ScalarModel scalarModel, final ObjectAdapter proposedAdapter) {
   final ObjectAdapter parentAdapter =
       scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK);
   final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
   try {
     final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter);
     return valid.isAllowed() ? null : valid.getReason();
   } catch (final Exception ex) {
     return ex.getLocalizedMessage();
   }
 }
Пример #9
0
 @Override
 public String disable(final ScalarModel scalarModel, final Where where) {
   final ObjectAdapter parentAdapter =
       scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK);
   final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
   try {
     final AuthenticationSession session = scalarModel.getAuthenticationSession();
     final Consent usable = property.isUsable(session, parentAdapter, where);
     return usable.isAllowed() ? null : usable.getReason();
   } catch (final Exception ex) {
     return ex.getLocalizedMessage();
   }
 }
Пример #10
0
  void updateObjectModel(
      final ModelImpl model,
      final ObjectSpecification objectSpecification,
      final List<OneToOneAssociation> objectProperties,
      final List<OneToManyAssociation> objectCollections) {

    final String objectType = objectTypeFor(objectSpecification);
    final String className = objectSpecification.getFullIdentifier();

    model.type("object").description(String.format("%s (%s)", objectType, className));

    for (OneToOneAssociation objectProperty : objectProperties) {
      model.property(objectProperty.getId(), propertyFor(objectProperty.getSpecification()));
    }

    for (OneToManyAssociation objectCollection : objectCollections) {
      final ObjectSpecification elementSpec = objectCollection.getSpecification();
      model.property(objectCollection.getId(), arrayPropertyOf(elementSpec));
    }
  }
Пример #11
0
 @Override
 public String getDescribedAs(final ScalarModel scalarModel) {
   final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
   final OneToOneAssociation property = propertyMemento.getProperty();
   return property.getDescription();
 }
Пример #12
0
 @Override
 public boolean hasAutoComplete(final ScalarModel scalarModel) {
   final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
   final OneToOneAssociation property = propertyMemento.getProperty();
   return property.hasAutoComplete();
 }