001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.isis.core.progmodel.facets.object.validprops; 021 022import org.apache.isis.applib.annotation.Where; 023import org.apache.isis.core.metamodel.adapter.ObjectAdapter; 024import org.apache.isis.core.metamodel.facetapi.FacetHolder; 025import org.apache.isis.core.metamodel.interactions.ObjectValidityContext; 026import org.apache.isis.core.metamodel.spec.feature.Contributed; 027import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation; 028import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation; 029 030public class ObjectValidPropertiesFacetImpl extends ObjectValidPropertiesFacetAbstract { 031 032 // REVIEW: should provide this rendering context, rather than hardcoding. 033 // the net effect currently is that class members annotated with 034 // @Hidden(where=Where.ANYWHERE) or @Disabled(where=Where.ANYWHERE) will indeed 035 // be hidden/disabled, but will be visible/enabled (perhaps incorrectly) 036 // for any other value for Where 037 private final Where where = Where.ANYWHERE; 038 039 public ObjectValidPropertiesFacetImpl(final FacetHolder holder) { 040 super(holder); 041 } 042 043 @Override 044 public String invalidReason(final ObjectValidityContext context) { 045 final StringBuilder buf = new StringBuilder(); 046 final ObjectAdapter adapter = context.getTarget(); 047 for (final ObjectAssociation property : adapter.getSpecification().getAssociations(Contributed.EXCLUDED, ObjectAssociation.Filters.PROPERTIES)) { 048 // ignore hidden properties 049 if (property.isVisible(context.getSession(), adapter, where).isVetoed()) { 050 continue; 051 } 052 // ignore disabled properties 053 if (property.isUsable(context.getSession(), adapter, where).isVetoed()) { 054 continue; 055 } 056 final OneToOneAssociation otoa = (OneToOneAssociation) property; 057 final ObjectAdapter value = otoa.get(adapter); 058 if (otoa.isAssociationValid(adapter, value).isVetoed()) { 059 if (buf.length() > 0) { 060 buf.append(", "); 061 } 062 buf.append(property.getName()); 063 } 064 } 065 if (buf.length() > 0) { 066 return "Invalid properties: " + buf.toString(); 067 } 068 return null; 069 } 070 071}