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; }
public SpecMemento getType() { if (type == null) { // lazy load if need be type = new SpecMemento(getProperty().getSpecification()); } return type; }
private Object valueRep() { final ObjectAdapter valueAdapter = objectMember.get(objectAdapter); if (valueAdapter == null) { return NullNode.getInstance(); } return DomainObjectReprRenderer.valueOrRef(resourceContext, valueAdapter, objectMember.getSpecification()); }
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); } }
public PropertyMemento( final OneToOneAssociation property, final IsisSessionFactory isisSessionFactory) { this( owningSpecFor(property, isisSessionFactory).getSpecId(), property.getIdentifier().toNameIdentityString(), property.getSpecification().getSpecId() ); }
public PropertyMemento( final OneToOneAssociation property, final IsisSessionFactory isisSessionFactory) { this( owningSpecFor(property, isisSessionFactory).getSpecId(), property.getIdentifier().toNameIdentityString(), property.getSpecification().getSpecId() ); }
public PropertyMemento(final OneToOneAssociation property) { this(new SpecMemento(owningSpecFor(property)), property.getIdentifier().toNameIdentityString(), new SpecMemento(property.getSpecification())); this.property = property; }
private void addLinkToReturnTypeIfAny() { final ObjectSpecification returnType = getObjectFeature().getSpecification(); if (returnType == null) { return; } final LinkBuilder linkBuilder = DomainTypeReprRenderer.newLinkToBuilder(getResourceContext(), Rel.RETURN_TYPE, returnType); getLinks().arrayAdd(linkBuilder.build()); }
private void addLinkToReturnTypeIfAny() { final ObjectSpecification returnType = getObjectFeature().getSpecification(); if (returnType == null) { return; } final LinkBuilder linkBuilder = DomainTypeReprRenderer.newLinkToBuilder(getRendererContext(), Rel.RETURN_TYPE, returnType); getLinks().arrayAdd(linkBuilder.build()); }
@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()); }
@Override @PUT @Path("/{domainType}/{instanceId}/properties/{propertyId}") @Consumes({ MediaType.WILDCARD }) @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ERROR }) public Response modifyProperty(@PathParam("domainType") String domainType, @PathParam("instanceId") final String instanceId, @PathParam("propertyId") final String propertyId, final InputStream body) { 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 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.createWithMessage(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } property.set(objectAdapter, argAdapter); return helper.propertyDetails(propertyId, MemberMode.MUTATING, Caching.NONE, getResourceContext().getWhere()); }
private void addLinkToReturnTypeIfAny() { final ObjectSpecification returnType = getObjectFeature().getSpecification(); if (returnType == null) { return; } final LinkBuilder linkBuilder = DomainTypeReprRenderer.newLinkToBuilder(getRendererContext(), Rel.RETURN_TYPE, returnType); getLinks().arrayAdd(linkBuilder.build()); }
@Override @PUT @Path("/{domainType}/{instanceId}/properties/{propertyId}") @Consumes({ MediaType.WILDCARD }) @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_OBJECT_PROPERTY, RestfulMediaType.APPLICATION_JSON_ERROR, MediaType.APPLICATION_XML, RestfulMediaType.APPLICATION_XML_OBJECT_PROPERTY, RestfulMediaType.APPLICATION_XML_ERROR }) public Response modifyProperty(@PathParam("domainType") String domainType, @PathParam("instanceId") final String instanceId, @PathParam("propertyId") final String propertyId, final InputStream body) { init(Where.OBJECT_FORMS, RepresentationService.Intent.NOT_APPLICABLE); setCommandExecutor(Command.Executor.USER); final ObjectAdapter objectAdapter = getObjectAdapterElseThrowNotFound(domainType, instanceId); final DomainResourceHelper helper = newDomainResourceHelper(objectAdapter); final ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(getResourceContext(), objectAdapter); final OneToOneAssociation property = accessHelper.getPropertyThatIsVisibleForIntent(propertyId, ObjectAdapterAccessHelper.Intent.MUTATE); final ObjectSpecification propertySpec = property.getSpecification(); final String bodyAsString = Util.asStringUtf8(body); final ObjectAdapter argAdapter = new JsonParserHelper(getResourceContext(), propertySpec).parseAsMapWithSingleValue( bodyAsString); final Consent consent = property.isAssociationValid(objectAdapter, argAdapter, InteractionInitiatedBy.USER); if (consent.isVetoed()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } property.set(objectAdapter, argAdapter, InteractionInitiatedBy.USER); return helper.propertyDetails( propertyId, MemberReprMode.WRITE ); }
@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(); } }
/** * Applies only for {@link OneToOneAssociation}s. */ @Override public SetValueResponse setValue(final SetValueRequest request) { final AuthenticationSession session = request.getSession(); final String fieldIdentifier = request.getFieldIdentifier(); final IdentityData targetIdentityData = request.getTarget(); final EncodableObjectData encodeableObjectData = request.getValue(); Assert.assertNotNull(encodeableObjectData); if (LOG.isDebugEnabled()) { LOG.debug("request setValue " + fieldIdentifier + " on " + targetIdentityData + " with " + encodeableObjectData + " for " + session); } final ObjectAdapter targetAdapter = getPersistentObjectAdapter(session, targetIdentityData); final OneToOneAssociation association = (OneToOneAssociation) targetAdapter.getSpecification().getAssociation(fieldIdentifier); ensureAssociationModifiableElseThrowException(session, targetAdapter, association); final String encodedObject = encodeableObjectData.getEncodedObjectData(); final ObjectSpecification specification = association.getSpecification(); final ObjectAdapter adapter = restoreLeafObject(encodedObject, specification); association.setAssociation(targetAdapter, adapter); return new SetValueResponse(getUpdates()); }
@Override public String parseAndValidate(final ScalarModel scalarModel, final String proposedPojoAsStr) { final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty(scalarModel.getSpecificationLoader()); ParseableFacet parseableFacet = property.getFacet(ParseableFacet.class); if (parseableFacet == null) { parseableFacet = property.getSpecification().getFacet(ParseableFacet.class); } try { final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK, scalarModel.getPersistenceSession(), scalarModel.getSpecificationLoader()); final ObjectAdapter currentValue = property.get(parentAdapter, InteractionInitiatedBy.USER); final ObjectAdapter proposedAdapter = parseableFacet.parseTextEntry(currentValue, proposedPojoAsStr, InteractionInitiatedBy.USER); final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter, InteractionInitiatedBy.USER); 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(); } }
@Override public String parseAndValidate(final ScalarModel scalarModel, final String proposedPojoAsStr) { final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty(scalarModel.getSpecificationLoader()); ParseableFacet parseableFacet = property.getFacet(ParseableFacet.class); if (parseableFacet == null) { parseableFacet = property.getSpecification().getFacet(ParseableFacet.class); } try { final ObjectAdapter parentAdapter = scalarModel.getParentEntityModel().load(); final ObjectAdapter currentValue = property.get(parentAdapter, InteractionInitiatedBy.USER); final ObjectAdapter proposedAdapter = parseableFacet.parseTextEntry(currentValue, proposedPojoAsStr, InteractionInitiatedBy.USER); final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter, InteractionInitiatedBy.USER); 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(); } }
@Override public void addPropertyValue( final OneToOneAssociation property, final PropertyDto propertyDto, final ObjectAdapter valueAdapter) { final String actionIdentifier = CommandUtil.memberIdentifierFor(property); final ObjectSpecification onType = property.getOnType(); final String objectType = onType.getSpecId().asString(); final String localId = property.getIdentifier().toNameIdentityString(); propertyDto.setLogicalMemberIdentifier(objectType + "#" + localId); propertyDto.setMemberIdentifier(actionIdentifier); final ObjectSpecification valueSpec = property.getSpecification(); final Class<?> valueType = valueSpec.getCorrespondingClass(); final ValueWithTypeDto newValue = CommonDtoUtils.newValueWithTypeDto( valueType, ObjectAdapter.Util.unwrap(valueAdapter), bookmarkService); propertyDto.setNewValue(newValue); }
final ObjectSpecification propertySpec = property.getSpecification(); final String id = property.getId(); final JsonRepresentation propertyRepr = propertiesList.getRepresentation("[id=%s]", id);
@Override public void doHandle(final PerformContext performContext) throws ScenarioBoundValueException { final ObjectAdapter onAdapter = performContext.getOnAdapter(); final ObjectMember nakedObjectMember = performContext.getObjectMember(); final List<ScenarioCell> argumentCells = performContext.getArgumentCells(); final OneToOneAssociation otoa = (OneToOneAssociation) nakedObjectMember; // set final PropertySetterFacet setterFacet = otoa.getFacet(PropertySetterFacet.class); if (setterFacet == null) { final CellBinding onMemberBinding = performContext.getPeer().getOnMemberBinding(); throw ScenarioBoundValueException.current(onMemberBinding, "(cannot set)"); } // safe to obtain since guaranteed by superclass final CellBinding arg0Binding = performContext.getPeer().getArg0Binding(); final ScenarioCell arg0Cell = argumentCells.get(0); // obtain existing as 'context' (used if this is a parsed @Value) final ObjectAdapter contextAdapter = otoa.get(onAdapter); // validate parameter final ObjectAdapter toSetAdapter = performContext.getPeer().getAdapter(contextAdapter, otoa.getSpecification(), arg0Binding, arg0Cell); final Consent validConsent = otoa.isAssociationValid(onAdapter, toSetAdapter); if (validConsent.isVetoed()) { throw ScenarioBoundValueException.current(arg0Binding, validConsent.getReason()); } setterFacet.setProperty(onAdapter, toSetAdapter); }