Search in sources :

Example 1 with History

use of io.crnk.example.springboot.domain.model.History in project crnk-framework by crnk-project.

the class HistoryFieldContributor method getResourceFields.

@Override
public List<ResourceField> getResourceFields(ResourceFieldContributorContext context) {
    // this method could be omitted if the history field is added regularly to Project and Task resource. This would be
    // simpler and recommended, but may not always be possible. Here we demonstrate doing it dynamically.
    InformationBuilder.Field fieldBuilder = context.getInformationBuilder().createResourceField();
    fieldBuilder.name("history");
    fieldBuilder.genericType(new TypeToken<List<History>>() {
    }.getType());
    fieldBuilder.oppositeResourceType("history");
    fieldBuilder.fieldType(ResourceFieldType.RELATIONSHIP);
    // field values are "null" on resource and we make use of automated lookup to the relationship repository
    // instead:
    fieldBuilder.lookupIncludeBehavior(LookupIncludeBehavior.AUTOMATICALLY_ALWAYS);
    fieldBuilder.accessor(new ResourceFieldAccessor() {

        @Override
        public Object getValue(Object resource) {
            return null;
        }

        @Override
        public void setValue(Object resource, Object fieldValue) {
        }
    });
    return Arrays.asList(fieldBuilder.build());
}
Also used : InformationBuilder(io.crnk.core.engine.information.InformationBuilder) ResourceFieldAccessor(io.crnk.core.engine.information.resource.ResourceFieldAccessor) TypeToken(com.google.common.reflect.TypeToken) History(io.crnk.example.springboot.domain.model.History)

Example 2 with History

use of io.crnk.example.springboot.domain.model.History in project crnk-framework by crnk-project.

the class HistoryResourceRepository method findOne.

@Override
public History findOne(UUID id, QuerySpec querySpec) {
    History history = new History();
    history.setId(id);
    history.setName("test");
    return history;
}
Also used : History(io.crnk.example.springboot.domain.model.History)

Example 3 with History

use of io.crnk.example.springboot.domain.model.History in project crnk-framework by crnk-project.

the class HistoryResourceRepository method findAll.

@Override
public ResourceList<History> findAll(Iterable<UUID> ids, QuerySpec querySpec) {
    DefaultResourceList list = new DefaultResourceList();
    for (UUID id : ids) {
        History history = new History();
        history.setId(id);
        history.setName("test");
        list.add(history);
    }
    return list;
}
Also used : DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) UUID(java.util.UUID) History(io.crnk.example.springboot.domain.model.History)

Example 4 with History

use of io.crnk.example.springboot.domain.model.History in project crnk-framework by crnk-project.

the class HistoryRelationshipRepository method findManyTargets.

@Override
public ResourceList<History> findManyTargets(Serializable sourceId, String fieldName, QuerySpec querySpec) {
    DefaultResourceList list = new DefaultResourceList();
    for (int i = 0; i < 10; i++) {
        History history = new History();
        history.setId(UUID.nameUUIDFromBytes(("historyElement" + i).getBytes()));
        history.setName("historyElement" + i);
        list.add(history);
    }
    return list;
}
Also used : DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) History(io.crnk.example.springboot.domain.model.History)

Aggregations

History (io.crnk.example.springboot.domain.model.History)4 DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)2 TypeToken (com.google.common.reflect.TypeToken)1 InformationBuilder (io.crnk.core.engine.information.InformationBuilder)1 ResourceFieldAccessor (io.crnk.core.engine.information.resource.ResourceFieldAccessor)1 UUID (java.util.UUID)1