@Override public EntityReference map( AssociationDescriptor associationDescriptor ) { Parameter param = queryAsForm.getFirst( associationDescriptor.qualifiedName().name() ); if( param == null ) { param = entityAsForm.getFirst( associationDescriptor.qualifiedName().name() ); } if( param != null ) { return EntityReference.parseEntityReference( param.getValue() ); } else { return null; } } },
@Override public Map<String, EntityReference> map( AssociationDescriptor descriptor ) { AssociationDescriptor associationDescriptor; try { String associationName = descriptor.qualifiedName().name(); AssociationStateDescriptor entityState = entityDescriptor.state(); associationDescriptor = entityState.getNamedAssociationByName( associationName ); } catch( IllegalArgumentException e ) { return Collections.emptyMap(); } AccessibleObject associationMethod = associationDescriptor.accessor(); NamedAssociation<Object> assoc = associationState.namedAssociationFor( associationMethod ); Map<String, EntityReference> refs = new LinkedHashMap<>( assoc.count() ); for( String name : assoc ) { refs.put( name, EntityReference.entityReferenceFor( assoc.get( name ) ) ); } return refs; } } );
private void serializeAssociations( final EntityState entityState, final Graph graph, URI entityUri, final Iterable<? extends AssociationDescriptor> associations, final boolean includeNonQueryable ) { ValueFactory values = graph.getValueFactory(); // Associations for( AssociationDescriptor associationType : associations ) { if( !( includeNonQueryable || associationType.queryable() ) ) { continue; // Skip non-queryable } EntityReference associatedId = entityState.associationValueOf( associationType.qualifiedName() ); if( associatedId != null ) { URI assocURI = values.createURI( associationType.qualifiedName().toURI() ); URI assocEntityURI = values.createURI( associatedId.toURI() ); graph.add( entityUri, assocURI, assocEntityURI ); } } }
@Override public Iterable<EntityReference> map( final AssociationDescriptor descriptor ) { AssociationDescriptor associationDescriptor; try { String associationName = descriptor.qualifiedName().name(); AssociationStateDescriptor entityState = entityDescriptor.state(); associationDescriptor = entityState.getManyAssociationByName( associationName ); } catch( IllegalArgumentException e ) { return Iterables.empty(); } ManyAssociation<?> state = associationState.manyAssociationFor( associationDescriptor.accessor() ); List<EntityReference> refs = new ArrayList<>( state.count() ); for( Object entity : state ) { refs.add( EntityReference.entityReferenceFor( entity ) ); } return refs; } },
private void serializeManyAssociationTypes( final EntityDescriptor entityDescriptor, final Graph graph, final URI entityTypeUri ) { ValueFactory values = graph.getValueFactory(); // ManyAssociations for( AssociationDescriptor manyAssociationType : entityDescriptor.state().manyAssociations() ) { URI associationURI = values.createURI( manyAssociationType.qualifiedName().toURI() ); graph.add( associationURI, Rdfs.DOMAIN, entityTypeUri ); graph.add( associationURI, Rdfs.TYPE, Rdfs.SEQ ); URI associatedURI = values.createURI( manyAssociationType.qualifiedName().toURI() ); graph.add( associationURI, Rdfs.RANGE, associatedURI ); graph.add( associationURI, Rdfs.RANGE, XMLSchema.ANYURI ); } }
private void serializeManyAssociations( final EntityState entityState, final Graph graph, final URI entityUri, final Iterable<? extends AssociationDescriptor> associations, final boolean includeNonQueryable ) { ValueFactory values = graph.getValueFactory(); // Many-Associations for( AssociationDescriptor associationType : associations ) { if( !( includeNonQueryable || associationType.queryable() ) ) { continue; // Skip non-queryable } BNode collection = values.createBNode(); graph.add( entityUri, values.createURI( associationType.qualifiedName().toURI() ), collection ); graph.add( collection, Rdfs.TYPE, Rdfs.SEQ ); ManyAssociationState associatedIds = entityState.manyAssociationValueOf( associationType.qualifiedName() ); for( EntityReference associatedId : associatedIds ) { URI assocEntityURI = values.createURI( associatedId.toURI() ); graph.add( collection, Rdfs.LIST_ITEM, assocEntityURI ); } } } }
@Override public EntityReference map( AssociationDescriptor descriptor ) { AssociationDescriptor associationDescriptor; try { associationDescriptor = entityDescriptor.state() .getAssociationByName( descriptor.qualifiedName().name() ); } catch( IllegalArgumentException e ) { return null; } AccessibleObject associationMethod = associationDescriptor.accessor(); Association<Object> association = associationState.associationFor( associationMethod ); return EntityReference.entityReferenceFor( association.get() ); } },
private void serializeAssociationTypes( final EntityDescriptor entityDescriptor, final Graph graph, final URI entityTypeUri ) { ValueFactory values = graph.getValueFactory(); // Associations for( AssociationDescriptor associationType : entityDescriptor.state().associations() ) { URI associationURI = values.createURI( associationType.qualifiedName().toURI() ); graph.add( associationURI, Rdfs.DOMAIN, entityTypeUri ); graph.add( associationURI, Rdfs.TYPE, Rdfs.PROPERTY ); URI associatedURI = values.createURI( Classes.toURI( Classes.RAW_CLASS.map( associationType.type() ) ) ); graph.add( associationURI, Rdfs.RANGE, associatedURI ); graph.add( associationURI, Rdfs.RANGE, XMLSchema.ANYURI ); } }
@Override public EntityReference map( AssociationDescriptor eAssocDesc ) { try { return EntityReference.entityReferenceFor( vState.associationFor( eAssocDesc.accessor() ) ); } catch( IllegalArgumentException assocNotFoundOnValue ) { // Find String Property and convert to Association String propName = eAssocDesc.qualifiedName().name(); try { PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( propName ); if( STRING_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) ) { String assocState = (String) vState.propertyFor( vPropDesc.accessor() ).get(); return EntityReference.parseEntityReference( assocState ); } return null; } catch( IllegalArgumentException propNotFoundOnValue ) { return null; } } } };
@Override public Map<String, EntityReference> map( AssociationDescriptor eAssocDesc ) { try { NamedAssociation<?> vAssocState = vState.namedAssociationFor( eAssocDesc.accessor() ); return NAMED_ASSOC_TO_ENTITY_REF_MAP.map( vAssocState ); } catch( IllegalArgumentException assocNotFoundOnValue ) { // Find Map<String,String> Property and convert to NamedAssociation String propName = eAssocDesc.qualifiedName().name(); try { PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( propName ); if( STRING_MAP_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) ) { Map<String, String> vAssocState = (Map) vState .propertyFor( vPropDesc.accessor() ).get(); return STRING_MAP_TO_ENTITY_REF_MAP.map( vAssocState ); } return Collections.EMPTY_MAP; } catch( IllegalArgumentException propNotFoundOnValue ) { return Collections.EMPTY_MAP; } } } };
@Override public Map<String, EntityReference> map( AssociationDescriptor eAssocDesc ) String assocName = eAssocDesc.qualifiedName().name(); try
@Override public Iterable<EntityReference> map( AssociationDescriptor eAssocDesc ) { try { ManyAssociation<Object> vAssocState = vState.manyAssociationFor( eAssocDesc.accessor() ); return MANY_ASSOC_TO_ENTITY_REF_ITERABLE.map( vAssocState ); } catch( IllegalArgumentException assocNotFoundOnValue ) { // Find Collection<String> Property and convert to ManyAssociation String propName = eAssocDesc.qualifiedName().name(); try { PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( propName ); if( STRING_COLLECTION_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) ) { Collection<String> vAssocState = (Collection) vState .propertyFor( vPropDesc.accessor() ).get(); return STRING_COLLEC_TO_ENTITY_REF_ITERABLE.map( vAssocState ); } return Iterables.empty(); } catch( IllegalArgumentException propNotFoundOnValue ) { return Iterables.empty(); } } } };
@Override public EntityReference map( AssociationDescriptor eAssocDesc ) { String assocName = eAssocDesc.qualifiedName().name(); try { AssociationDescriptor vAssocDesc = vStateDesc.getAssociationByName( assocName ); Object assocEntity = vState.associationFor( vAssocDesc.accessor() ).get(); return assocEntity == null ? null : EntityReference.entityReferenceFor( assocEntity ); } catch( IllegalArgumentException assocNotFoundOnValue ) { // Association not found on Value, find Property<String> and convert to Association try { PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( assocName ); if( STRING_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) ) { String assocId = (String) vState.propertyFor( vPropDesc.accessor() ).get(); return assocId == null ? null : EntityReference.parseEntityReference( assocId ); } return null; } catch( IllegalArgumentException propNotFoundOnValue ) { return null; } } } };
= vStateDesc.getAssociationByQualifiedName( eAssocDesc.qualifiedName() ); eAssoc.set( vState.associationFor( vAssocDesc.accessor() ).get() ); = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() ); if( STRING_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) ) = vStateDesc.getManyAssociationByQualifiedName( eAssocDesc.qualifiedName() ); ManyAssociation<Object> vManyAssoc = vState.manyAssociationFor( vAssocDesc.accessor() ); for( Object assoc : eManyAssoc.toList() ) = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() ); if( STRING_COLLECTION_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) ) = vStateDesc.getNamedAssociationByQualifiedName( eAssocDesc.qualifiedName() ); NamedAssociation<Object> vNamedAssoc = vState.namedAssociationFor( vAssocDesc.accessor() ); for( String assocName : Iterables.toList( eNamedAssoc ) ) = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() ); if( STRING_MAP_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) )
@Override public Iterable<EntityReference> map( AssociationDescriptor eAssocDesc ) String assocName = eAssocDesc.qualifiedName().name(); try
try AssociationDescriptor vAssocDesc = vStateDesc.getAssociationByName( eAssocDesc.qualifiedName().name() ); eAssoc.set( vState.associationFor( vAssocDesc.accessor() ).get() ); = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() ); if( STRING_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) ) = vStateDesc.getManyAssociationByName( eAssocDesc.qualifiedName().name() ); ManyAssociation<Object> vManyAss = vState.manyAssociationFor( vAssDesc.accessor() ); for( Object ass : eManyAssoc.toList() ) = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() ); if( STRING_COLLECTION_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) ) = vStateDesc.getNamedAssociationByName( eAssocDesc.qualifiedName().name() ); NamedAssociation<Object> vNamedAssoc = vState.namedAssociationFor( vAssocDesc.accessor() ); for( String assocName : Iterables.toList( eNamedAssoc ) ) = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() ); if( STRING_MAP_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) )