deleteEntityUponRemove = map.isDeleteEntityUponRemove();
}
String valuePropertyName = "value";
String valuePropertyFriendlyName = null;
if (serverMetadata != null) {
MapStructure structure = (MapStructure) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.MAPSTRUCTURE);
if (structure instanceof SimpleValueMapStructure) {
valuePropertyFriendlyName = ((SimpleValueMapStructure) structure).getValuePropertyFriendlyName();
} else {
valuePropertyFriendlyName = "";
}
}
if (map.getValuePropertyFriendlyName()!=null) {
valuePropertyFriendlyName = map.getValuePropertyFriendlyName();
}
if (map.getMediaField() != null) {
metadata.setMediaField(map.getMediaField());
}
if (map.getValueClass() != null && !void.class.getName().equals(map.getValueClass())) {
metadata.setValueClassName(map.getValueClass());
}
if (metadata.getValueClassName() == null) {
java.lang.reflect.Type type = field.getGenericType();
if (type instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) type;
Class<?> clazz = (Class<?>) pType.getActualTypeArguments()[1];
Class<?>[] entities = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(clazz);
if (!ArrayUtils.isEmpty(entities)) {
metadata.setValueClassName(entities[entities.length-1].getName());
}
}
}
if (metadata.getValueClassName() == null) {
if (!StringUtils.isEmpty(field.getManyToManyTargetEntity())) {
metadata.setValueClassName(field.getManyToManyTargetEntity());
}
}
if (metadata.getValueClassName() == null) {
metadata.setValueClassName(String.class.getName());
}
Boolean simpleValue = null;
if (map.getSimpleValue()!= null && map.getSimpleValue()!= UnspecifiedBooleanType.UNSPECIFIED) {
simpleValue = map.getSimpleValue()==UnspecifiedBooleanType.TRUE;
}
if (simpleValue==null) {
java.lang.reflect.Type type = field.getGenericType();
if (type instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) type;
Class<?> clazz = (Class<?>) pType.getActualTypeArguments()[1];
Class<?>[] entities = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(clazz);
simpleValue = ArrayUtils.isEmpty(entities);
}
}
if (simpleValue==null) {
//ManyToMany manyToMany = field.getAnnotation(ManyToMany.class);
if (!StringUtils.isEmpty(field.getManyToManyTargetEntity())) {
simpleValue = false;
}
}
if (simpleValue == null) {
throw new IllegalArgumentException("Unable to infer if the value for the map is of a complex or simple type based on any parameterized type or ManyToMany annotation. Please explicitly set the isSimpleValue property.");
}
metadata.setSimpleValue(simpleValue);
if (map.getKeys() != null) {
metadata.setKeys(map.getKeys());
}
if (map.getMapKeyValueProperty() != null) {
metadata.setMapKeyValueProperty(map.getMapKeyValueProperty());
}
if (map.getMapKeyOptionEntityClass()!=null) {
if (!void.class.getName().equals(map.getMapKeyOptionEntityClass())) {
metadata.setMapKeyOptionEntityClass(map.getMapKeyOptionEntityClass());
} else {
metadata.setMapKeyOptionEntityClass("");
}
}
if (map.getMapKeyOptionEntityDisplayField() != null) {
metadata.setMapKeyOptionEntityDisplayField(map.getMapKeyOptionEntityDisplayField());
}
if (map.getMapKeyOptionEntityValueField()!=null) {
metadata.setMapKeyOptionEntityValueField(map.getMapKeyOptionEntityValueField());
}
if (map.getForceFreeFormKeys() != null) {
if (!map.getForceFreeFormKeys() && ArrayUtils.isEmpty(metadata.getKeys()) && (StringUtils.isEmpty(metadata.getMapKeyOptionEntityClass()) || StringUtils.isEmpty(metadata.getMapKeyOptionEntityValueField()) || StringUtils.isEmpty(metadata.getMapKeyOptionEntityDisplayField()))) {
throw new IllegalArgumentException("Could not ascertain method for generating key options for the annotated map ("+field.getName()+"). Must specify either an array of AdminPresentationMapKey values for the keys property, or utilize the mapOptionKeyClass, mapOptionKeyDisplayField and mapOptionKeyValueField properties. If you wish to allow free form entry for key values, then set forceFreeFormKeys on AdminPresentationMap.");
}
}
MapStructure mapStructure;
if (serverMetadata != null) {
ForeignKey foreignKey = (ForeignKey) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY);
foreignKey.setManyToField(parentObjectIdField);
foreignKey.setForeignKeyClass(parentObjectClass);
if (metadata.isSimpleValue()) {
mapStructure = (SimpleValueMapStructure) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.MAPSTRUCTURE);
mapStructure.setKeyClassName(keyClassName);
mapStructure.setKeyPropertyName(keyPropertyName);
mapStructure.setKeyPropertyFriendlyName(keyPropertyFriendlyName);
mapStructure.setValueClassName(metadata.getValueClassName());
((SimpleValueMapStructure) mapStructure).setValuePropertyName(valuePropertyName);
((SimpleValueMapStructure) mapStructure).setValuePropertyFriendlyName(valuePropertyFriendlyName);
mapStructure.setMapProperty(prefix + field.getName());
mapStructure.setMutable(metadata.isMutable());
} else {
mapStructure = (MapStructure) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.MAPSTRUCTURE);
mapStructure.setKeyClassName(keyClassName);
mapStructure.setKeyPropertyName(keyPropertyName);
mapStructure.setKeyPropertyFriendlyName(keyPropertyFriendlyName);
mapStructure.setValueClassName(metadata.getValueClassName());
mapStructure.setMapProperty(prefix + field.getName());
mapStructure.setDeleteValueEntity(deleteEntityUponRemove);
mapStructure.setMutable(metadata.isMutable());
}
} else {
ForeignKey foreignKey = new ForeignKey(parentObjectIdField, parentObjectClass);
persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.FOREIGNKEY, foreignKey);
if (metadata.isSimpleValue()) {
mapStructure = new SimpleValueMapStructure(keyClassName, keyPropertyName, keyPropertyFriendlyName, metadata.getValueClassName(), valuePropertyName, valuePropertyFriendlyName, prefix + field.getName(), mapKeyValueProperty);
mapStructure.setMutable(metadata.isMutable());
} else {
mapStructure = new MapStructure(keyClassName, keyPropertyName, keyPropertyFriendlyName, metadata.getValueClassName(), prefix + field.getName(), deleteEntityUponRemove, mapKeyValueProperty);
mapStructure.setMutable(metadata.isMutable());
}
persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.MAPSTRUCTURE, mapStructure);
}
if (!StringUtils.isEmpty(map.getManyToField())) {
mapStructure.setManyToField(map.getManyToField());
}
if (mapStructure.getManyToField() == null) {
//try to infer the value
if (field.getManyToManyMappedBy() != null) {
mapStructure.setManyToField(field.getManyToManyMappedBy());
}
}
if (mapStructure.getManyToField() == null) {
//try to infer the value
if (field.getOneToManyMappedBy() != null) {
mapStructure.setManyToField(field.getOneToManyMappedBy());
}
}
if (map.getExcluded() != null) {
if (LOG.isDebugEnabled()) {