@Override public boolean test( HasIdentity item ) { return id.equals( item.identity().get() ); } }
@Override public boolean equals( Object o ) { try { HasIdentity other = ( (HasIdentity) o ); return other != null && other.identity().get().equals( reference.identity() ); } catch( ClassCastException e ) { return false; } }
private File diskStorePath() { String stringIdentity = identity.identity().get().toString(); if( fileConfiguration != null ) { return new File( fileConfiguration.cacheDirectory(), stringIdentity ); } return new File( System.getProperty( "java.io.tmpdir" ), stringIdentity ); }
@Override public String name() { return manager.extractName( me.identity().get() ); }
protected EntityReference getEntityReference( Object composite ) { if( composite == null ) { return null; } return EntityReference.create(((HasIdentity) composite).identity().get()); }
private String cacheManagerThreadPoolName( String name ) { return identity.identity().get().toString() + "-" + name; } }
@Override public Class type() { return manager.extractType( me.identity().get() ); } }
/** * @param object an EntityComposite * @return the EntityReference for the given EntityComposite */ public static EntityReference entityReferenceFor(Object object) { Objects.requireNonNull( object ); if( object instanceof Identity ) { return new EntityReference( ((Identity) object) ); } if( object instanceof HasIdentity ) { return new EntityReference( ((HasIdentity) object).identity().get() ); } throw new IllegalArgumentException( "Can not get an entity reference for " + object.getClass() ); }
/** * @param object an EntityComposite * @return the EntityReference for the given EntityComposite */ public static EntityReference entityReferenceFor(Object object) { Objects.requireNonNull( object ); if( object instanceof Identity ) { return new EntityReference( ((Identity) object) ); } if( object instanceof HasIdentity ) { return new EntityReference( ((HasIdentity) object).identity().get() ); } throw new IllegalArgumentException( "Can not get an entity reference for " + object.getClass() ); }
@SuppressWarnings( "unchecked" ) private List<EntityRef> getEntityRefs( Reference base ) { ArrayList result = new ArrayList<>(); Property<Class<T>> property = parameters.entityType(); Class<T> entityType = property.get(); CrudRepository<T> repository = locator.find( entityType ); Iterable<T> all = repository.findAll(); Stream<T> stream = StreamSupport.stream( all.spliterator(), false ); stream .map( entity -> entity.identity().get() ) .map( identity -> resourceBuilder.createEntityRef( identity, base ) ) .forEach( result::add ); return result; } }
@Override public boolean remove( T entity ) { Objects.requireNonNull( entity, "entity" ); checkImmutable(); checkType( entity ); return manyAssociationState.remove( EntityReference.create( ((HasIdentity) entity).identity().get() ) ); }
@Override public boolean put( String name, T entity ) { Objects.requireNonNull( entity, "entity" ); checkImmutable(); try { checkType( entity ); } catch( IllegalArgumentException e ) { throw new IllegalArgumentException( "Named association [" + name +"] must have Identity: " + entity ); } associationInfo.checkConstraints( entity ); return namedAssociationState.put( name, EntityReference.create( ( (HasIdentity) entity ).identity().get() ) ); }
storeId = hasIdentity.identity().get().toString(); String pathName = config.get().directory().get(); if( pathName == null )
@Override public boolean add( int i, T entity ) { Objects.requireNonNull( entity, "entity" ); checkImmutable(); checkType( entity ); associationInfo.checkConstraints( entity ); return manyAssociationState.add( i, EntityReference.create( ((HasIdentity) entity ).identity().get()) ); }
Identity identity = instance instanceof HasIdentity ? ( (HasIdentity) instance ).identity().get() : null; exception.setIdentity( identity ); if( instance instanceof CompositeInstance )
@Override protected void activateElasticSearch() throws Exception { configuration.refresh(); ElasticSearchIndexingConfiguration config = configuration.get(); String clusterName = config.clusterName().get() == null ? DEFAULT_CLUSTER_NAME : config.clusterName().get(); index = config.index().get() == null ? DEFAULT_INDEX_NAME : config.index().get(); indexNonAggregatedAssociations = config.indexNonAggregatedAssociations().get(); Identity identity = hasIdentity.identity().get(); File homeDir = new File( new File( fileConfig.temporaryDirectory(), identity.toString() ), "home" ); File logsDir = new File( fileConfig.logDirectory(), identity.toString() ); File dataDir = new File( fileConfig.dataDirectory(), identity.toString() ); File confDir = new File( fileConfig.configurationDirectory(), identity.toString() ); Stream.of( homeDir, logsDir, dataDir, confDir ).forEach( File::mkdirs ); Settings settings = Settings.builder() .put( "cluster.name", clusterName ) .put( "path.home", homeDir.getAbsolutePath() ) .put( "path.logs", logsDir.getAbsolutePath() ) .put( "path.data", dataDir.getAbsolutePath() ) .put( "path.conf", confDir.getAbsolutePath() ) .put( "transport.type", "local" ) .put( "http.enabled", false ) .build(); node = new Node( settings ); node.start(); client = node.client(); }
@Override public void set( T newValue ) throws IllegalArgumentException { checkImmutable(); checkType( newValue ); associationInfo.checkConstraints( newValue ); // Change association Identity identity = newValue != null ? ( (HasIdentity) newValue ).identity().get() : null; associationState.set( EntityReference.create( identity ) ); }
/** * Create a new EQUALS specification for an Association. * * @param <T> Association type * @param association an Association * @param value its value * * @return a new EQUALS specification for an Association. */ public static <T> EqPredicate<Identity> eq( Association<T> association, T value ) { return new EqPredicate<>( new PropertyFunction<>( null, association(association), null, null, IDENTITY_METHOD), ((HasIdentity) value).identity().get()); }
/** * Create a new EQUALS specification for an Association. * * @param <T> Association type * @param association an Association * @param value its value * * @return a new EQUALS specification for an Association. */ public static <T> EqPredicate<Identity> eq( Association<T> association, T value ) { return new EqPredicate<>( new PropertyFunction<>( null, association(association), null, null, IDENTITY_METHOD), ((HasIdentity) value).identity().get()); }
@Override public Iterable<File> locateAttachedFiles() { File baseDir = spi.entityDescriptorFor( meAsIdentity ).metaInfo( File.class ); List<File> list = new ArrayList<>(); for( MyEnum eachValue : MyEnum.values() ) { list.add( new File( baseDir, meAsIdentity.identity().get() + "." + eachValue.name() ) ); } return list; }