Skip to content

Instantly share code, notes, and snippets.

List<ModelAnnotation<?>> annotations = new ArrayList<ModelAnnotation<?>>();
annotations.add( new ModelAnnotation<Measure>( "field1", new Measure() ) );
annotations.add( new ModelAnnotation<Attribute>( "field2", new Attribute() ) );
annotations.add( new ModelAnnotation<Dimension>( "field2", new Dimension() ) );
annotations.add( new ModelAnnotation<HierarchyLevel>( "field3", new HierarchyLevel() ) );
annotations.add( new ModelAnnotation<Measure>( "field4", new Measure() ) );
for ( ModelAnnotation<?> modelAnnotation : annotations ) {
// do something with modelAnnotation - what is it? a measure, dimension, etc....
}
if ( modelAnnotation.isMeasure() ) {
ModelAnnotation<Measure> measureAnnotation = (ModelAnnotation<Measure>) modelAnnotation;
}
plugins {
id 'org.springframework.boot' version '1.5.2.RELEASE'
}
apply plugin: 'groovy'
repositories {
jcenter()
mavenCentral()
}
@Component
@CompileStatic
@Log4j
class DispatcherService {
@Autowired
List<Handler> handlers
Response dispatch(Request request) {
log.info("request: ${request}")
@Entity
@ToString
@CompileStatic
class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id
String firstName
String lastName
import com.serverless.persistence.entities.User
import org.springframework.data.repository.CrudRepository
interface UserRepository extends CrudRepository<User, Long> {
List<User> findByLastName(String lastName)
}
interface Handler {
boolean route(Request request)
Response respond(Request request)
}
@Component
@Log4j
@CompileStatic
class FindUsersByLastName implements Handler {
@Autowired
private UserRepository userRepository
@Override
boolean route(final Request request) {
@Component
@Log4j
@CompileStatic
class GetUsers implements Handler {
@Autowired
private UserRepository userRepository
@Override
boolean route(final Request request) {
@Component
@Log4j
@CompileStatic
class CreateUser implements Handler {
@Autowired
private UserRepository userRepository
@Override
boolean route(Request request) {