@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(); final ObjectAdapter currentValue = property.get(parentAdapter); final ObjectAdapter proposedAdapter = parseableFacet.parseTextEntry(currentValue, proposedPojoAsStr); final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter); return valid.isAllowed() ? null : valid.getReason(); } catch (final Exception ex) { return ex.getLocalizedMessage(); } }
final ObjectSpecification propertySpec = property.getSpecification(); final String id = property.getId(); final JsonRepresentation propertyRepr = propertiesList.getRepresentation("[id=%s]", id); if (propertyRepr == null) { if (property.isMandatory()) { throw new IllegalArgumentException(String.format("Mandatory field %s missing", property.getName())); final Consent usable = property.isUsable(resourceContext.getAuthenticationSession() , objectAdapter, resourceContext.getWhere()); if (usable.isVetoed()) { propertyRepr.mapPut("invalidReason", usable.getReason()); final Consent consent = property.isAssociationValid(objectAdapter, valueAdapter); if (consent.isAllowed()) { try { property.set(objectAdapter, valueAdapter); } catch (final IllegalArgumentException ex) { propertyRepr.mapPut("invalidReason", ex.getMessage());
private Object propertyChoices() { final ObjectAdapter[] choiceAdapters = objectMember.getChoices(objectAdapter); if (choiceAdapters == null || choiceAdapters.length == 0) { return null; } final List<Object> list = Lists.newArrayList(); for (final ObjectAdapter choiceAdapter : choiceAdapters) { final ObjectSpecification objectSpec = objectMember.getSpecification(); list.add(DomainObjectReprRenderer.valueOrRef(resourceContext, choiceAdapter, objectSpec)); } return list; }
private void setUpReferenceField(final ObjectAdapter adapter, final OneToOneAssociation field, final Data data, final KnownObjectsRequest knownObjects) { ObjectAdapter associate; associate = deserializeObject(data, knownObjects); if (LOG.isDebugEnabled()) { LOG.debug("setting association for field " + field.getId() + ": " + associate); } field.initAssociation(adapter, associate); }
private void updateOneToOneAssociation(final ObjectAdapter object, final OneToOneAssociation field, final Data fieldData) { if (fieldData == null) { field.initAssociation(object, null); } else { final ObjectAdapter ref = recreateReference(fieldData); if (field.get(object) != ref) { if (LOG.isDebugEnabled()) { LOG.debug(" association " + field + " changed to " + ref.getOid()); } field.initAssociation(object, ref); } } }
@Override @PUT @Path("/{oid}/properties/{propertyId}") @Consumes({ MediaType.WILDCARD }) @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ERROR }) public Response modifyProperty(@PathParam("oid") final String oidStr, @PathParam("propertyId") final String propertyId, final InputStream body) { init(Where.OBJECT_FORMS); final ObjectAdapter objectAdapter = getObjectAdapter(oidStr); final DomainResourceHelper helper = new DomainResourceHelper(getResourceContext(), objectAdapter); final OneToOneAssociation property = helper.getPropertyThatIsVisibleAndUsable(propertyId, Intent.MUTATE, getResourceContext().getWhere()); final ObjectSpecification propertySpec = property.getSpecification(); final String bodyAsString = DomainResourceHelper.asStringUtf8(body); final ObjectAdapter argAdapter = helper.parseAsMapWithSingleValue(propertySpec, bodyAsString); final Consent consent = property.isAssociationValid(objectAdapter, argAdapter); if (consent.isVetoed()) { throw RestfulObjectsApplicationException.create(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } property.set(objectAdapter, argAdapter); return helper.propertyDetails(objectAdapter, propertyId, MemberMode.MUTATING, Caching.NONE, getResourceContext().getWhere()); }
allowing(mockPasswordMember).isVisible(mockEmployeeAdapter, InteractionInitiatedBy.USER, Where.ANYWHERE); will(returnValue(visibilityConsent)); allowing(mockPasswordMember).isUsable(mockEmployeeAdapter, InteractionInitiatedBy.USER, Where.ANYWHERE ); will(returnValue(usabilityConsent)); allowing(mockPasswordMember).isAssociationValid(mockEmployeeAdapter, mockPasswordAdapter, InteractionInitiatedBy.USER); will(returnValue(validityConsent)); context.checking(new Expectations() { allowing(mockPasswordMember).streamFacets(); will(returnValue(facets.stream())); oneOf(mockPasswordMember).set(mockEmployeeAdapter, mockPasswordAdapter, InteractionInitiatedBy.USER); context.checking(new Expectations() { allowing(mockPasswordMember).streamFacets(); will(returnValue(facets.stream())); oneOf(mockPasswordMember).get(mockEmployeeAdapter, InteractionInitiatedBy.USER); will(returnValue(mockPasswordAdapter));
allowing(mockPasswordMember).isVisible(mockEmployeeAdapter, InteractionInitiatedBy.USER, Where.ANYWHERE); will(returnValue(visibilityConsent)); allowing(mockPasswordMember).isUsable(mockEmployeeAdapter, InteractionInitiatedBy.USER, Where.ANYWHERE ); will(returnValue(usabilityConsent)); allowing(mockPasswordMember).isAssociationValid(mockEmployeeAdapter, mockPasswordAdapter, InteractionInitiatedBy.USER); will(returnValue(validityConsent)); context.checking(new Expectations() { allowing(mockPasswordMember).getFacets(with(any(Filter.class))); will(returnValue(facets)); oneOf(mockPasswordMember).set(mockEmployeeAdapter, mockPasswordAdapter, InteractionInitiatedBy.USER); context.checking(new Expectations() { allowing(mockPasswordMember).getFacets(with(any(Filter.class))); will(returnValue(facets)); oneOf(mockPasswordMember).get(mockEmployeeAdapter, InteractionInitiatedBy.USER); will(returnValue(mockPasswordAdapter));
@Override public void doHandle(final PerformContext performContext) { final ObjectAdapter onAdapter = performContext.getOnAdapter(); final ObjectMember nakedObjectMember = performContext.getObjectMember(); final OneToOneAssociation otoa = (OneToOneAssociation) nakedObjectMember; result = otoa.get(onAdapter); }
@Override @DELETE @Path("/{domainType}/{instanceId}/properties/{propertyId}") @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ERROR }) public Response clearProperty(@PathParam("domainType") String domainType, @PathParam("instanceId") final String instanceId, @PathParam("propertyId") final String propertyId) { init(Where.OBJECT_FORMS); final ObjectAdapter objectAdapter = getObjectAdapterElseThrowNotFound(domainType, instanceId); final DomainResourceHelper helper = new DomainResourceHelper(getResourceContext(), objectAdapter); final OneToOneAssociation property = helper.getPropertyThatIsVisibleForIntent(propertyId, Intent.MUTATE, getResourceContext().getWhere()); final Consent consent = property.isAssociationValid(objectAdapter, null); if (consent.isVetoed()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } property.set(objectAdapter, null); return helper.propertyDetails(propertyId, MemberMode.MUTATING, Caching.NONE, getResourceContext().getWhere()); }
will(returnValue(TestObject.class.getName())); atLeast(1).of(nameField).isNotPersisted(); will(returnValue(false)); atLeast(1).of(nameField).isOneToManyAssociation(); will(returnValue(false)); atLeast(1).of(nameField).getSpecification(); will(returnValue(nameSpecification)); atLeast(1).of(nameField).getId(); will(returnValue("name-field")); will(returnValue(ResolveState.RESOLVED)); atLeast(1).of(nameField).get(rootAdapter); will(returnValue(nameAdapter));
private void setUpEncodedField(final ObjectAdapter adapter, final OneToOneAssociation field, final Data data) { String value; if (data instanceof NullData) { field.initAssociation(adapter, null); } else { value = ((EncodableObjectData) data).getEncodedObjectData(); final EncodableFacet encoder = field.getSpecification().getFacet(EncodableFacet.class); final ObjectAdapter valueAdapter = encoder.fromEncodedString(value); if (LOG.isDebugEnabled()) { LOG.debug("setting value for field " + field.getId() + ": " + valueAdapter); } field.initAssociation(adapter, valueAdapter); } }
private Object valueRep() { final ObjectAdapter valueAdapter = objectMember.get(objectAdapter); if (valueAdapter == null) { return NullNode.getInstance(); } return DomainObjectReprRenderer.valueOrRef(resourceContext, valueAdapter, objectMember.getSpecification()); }
private void addValue() { final ObjectAdapter valueAdapter = objectMember.get(objectAdapter); final ObjectSpecification spec = valueAdapter != null? valueAdapter.getSpecification(): objectMember.getSpecification(); final RenderFacet renderFacet = objectMember.getFacet(RenderFacet.class); boolean eagerlyRender = renderFacet != null && renderFacet.value() == Type.EAGERLY && rendererContext.canEagerlyRender(valueAdapter);
public PropertyMemento( final OneToOneAssociation property, final IsisSessionFactory isisSessionFactory) { this( owningSpecFor(property, isisSessionFactory).getSpecId(), property.getIdentifier().toNameIdentityString(), property.getSpecification().getSpecId() ); }
@Override public String invalidReason(final ObjectValidityContext context) { final StringBuilder buf = new StringBuilder(); final ObjectAdapter adapter = context.getTarget(); for (final ObjectAssociation property : adapter.getSpecification().getAssociations(ObjectAssociationFilters.PROPERTIES)) { // ignore hidden properties if (property.isVisible(context.getSession(), adapter).isVetoed()) { continue; } // ignore disabled properties if (property.isUsable(context.getSession(), adapter).isVetoed()) { continue; } final OneToOneAssociation otoa = (OneToOneAssociation) property; final ObjectAdapter value = otoa.get(adapter); if (otoa.isAssociationValid(adapter, value).isVetoed()) { if (buf.length() > 0) { buf.append(", "); } buf.append(property.getName()); } } if (buf.length() > 0) { return "Invalid properties: " + buf.toString(); } return null; }
@Override protected Consent determineConsent(final PerformContext performContext, final ObjectAdapter toValidateAdapter) { final ObjectAdapter onAdapter = performContext.getOnAdapter(); final OneToOneAssociation otoa = (OneToOneAssociation) performContext.getObjectMember(); return otoa.isAssociationValid(onAdapter, toValidateAdapter); }
public static LinkBuilder newLinkToBuilder(final ResourceContext resourceContext, final Rel rel, final ObjectSpecification objectSpecification, final OneToOneAssociation property) { final String typeFullName = objectSpecification.getFullIdentifier(); final String propertyId = property.getId(); final String url = "domainTypes/" + typeFullName + "/properties/" + propertyId; return LinkBuilder.newBuilder(resourceContext, rel, RepresentationType.PROPERTY_DESCRIPTION, url); }
will(returnValue(passwordValue)); allowing(mockPasswordMember).getIdentifier(); will(returnValue(mockPasswordIdentifier)); will(returnValue(mockPasswordMember)); allowing(mockPasswordMember).getName(); will(returnValue("password")); will(returnValue(session)); allowing(mockPasswordMember).isOneToOneAssociation(); will(returnValue(true)); allowing(mockPasswordMember).isOneToManyAssociation(); will(returnValue(false));
private static void setObjectFromPropertyIfVisible( final ScalarModel scalarModel, final OneToOneAssociation property, final ObjectAdapter parentAdapter) { final Where where = scalarModel.getRenderingHint().asWhere(); final Consent visibility = property.isVisible(parentAdapter, InteractionInitiatedBy.FRAMEWORK, where); final ObjectAdapter associatedAdapter; if (visibility.isAllowed()) { associatedAdapter = property.get(parentAdapter, InteractionInitiatedBy.USER); } else { associatedAdapter = null; } scalarModel.setObject(associatedAdapter); }