Wicket1.4 to 7 migration - wicket-7

I'm New to Wicket.
Working on Wicket upgrade 1.4->7.
Part of this,I struck with below logic and not sure how to fix this. Looking for
helping hand to fix it.
list.add(new PropertyColumn(new Model("Max Upfront Comm Percent"), "maxUpfrontCommPercent","maxUpfrontCommPercent")
{
private static final long serialVersionUID = 1L;
#Override
protected IConverter getConverter(Class<?> arg0) {
return new BigDecimalConverter();
}
}.setInitialSize(110));
I'm looking for solution how this wicket4 logic needs to be run in wicket 7.
Seeing error:The method getConverter(Class<?>) of type new PropertyColumn(){} must override or implement a supertype method
- IConverter is a raw type. References to generic type IConverter should be parameterized
Thank you
Santosh

Related

HazelcastException: Cannot use EqualPredicate predicate with an array or a collection attribute

I am storing users and their locations in hazelcast. When i fire query on locations iam facing exception.
I am using hazelcast 3.12.1 version
i followed hazelcast's reference manual
https://docs.hazelcast.org/docs/latest/manual/html-single/#querying-in-collections-and-arrays
Predicate pagingPredicate = new PagingPredicate<String, User>(
new SqlPredicate("userActive AND ( locations=null OR ( locations[any].country='India' AND locations[any].state='Telangana' AND locations[any].city='Hyderabad' ) )"), PRICE_COMPARATOR, 2);
return usersMap.values(pagingPredicate)
and my PriceComparator.java
public class PriceComparator implements Comparator<Entry<String, User>>,
Serializable {
private static final long serialVersionUID = -198157764684077461L;
#Override
public int compare(Entry<String, User> o1, Entry<String, User> o2) {
return Double.compare(o2.getValue().getSalary().doubleValue(),
o1.getValue().getSalary().doubleValue());
}
}
I expect cache should return me with some values, but instead iam facing exception
java.lang.IllegalArgumentException: Cannot use EqualPredicate predicate with an array or a collection attribute
Can anyone help me on this.
Finally issue got resolved.
This was an issue because of condition locations=null. When I replaced this condition with locations.size=0 it worked fine.
I am unable to figured it out why null check on collection throws an exception??
If anyone has an answer please let me know

Sprint Data Rest extend PagingAndSortingRepository with custom method

My objective is to add a custom convenience method to a Spring Data REST API without creating my own controller.
According to the documentation here I have extended PagingAndSortingRepository in the following manner:
Repository:
#RepositoryRestResource
public interface PartyRestRepository extends PagingAndSortingRepository<Party, String>, CustomPartyRestRepository {
}
Interface with my method:
public interface CustomPartyRestRepository {
void dynamicPartyCreation(final String name);
}
Implementation:
public class CustomPartyRestRepositoryImpl implements CustomPartyRestRepository {
#Autowired
private PartyService partyService;
#Autowired
private PartyRepository partyRepository;
#Autowired
private HeroService heroService;
#Override
public void dynamicPartyCreation(final String name) {
final Party party = this.partyService.createParty(name);
final List<Hero> heroes = IntStream.range(0, 3)
.mapToObj(i -> this.heroService.createHero(String.format("Hero %d for %s", i, name)))
.collect(Collectors.toList());
party.setMembers(heroes);
this.partyRepository.save(party);
}
}
When I do GET localhost:8080/profile/parties/, I see that Spring has picked up my method and is exposing it:
<...cut...>
{
"name": "dynamicPartyCreation",
"type": "SAFE"
}
<..cut..>
But I can't seem to use it. GET localhost:8080/parties/dynamicPartyCreation/ results in 404, as does POST, with body or without, with query param or not. A PUT simply creates a party and ignores the /parties/dynamicPartyCreation/ part of the url (meaning, my method isn't called). I have tried a million combinations but I can't use it.
What am I doing wrong?
Well, interesting, I never thought it could work this way...
try
return this.partyRepository.save(party);
Although I don't understand how can it work at all, when you basically #autowired PartyRepositoryCustom into itself...
So maybe it should be something like this:
public class CustomPartyRestRepositoryImpl implements CustomPartyRestRepository {
#Autowired
private PartyService partyService;
#Autowired
private ListableBeanFactory beanFactory;
#Autowired
private HeroService heroService;
#Override
public Party dynamicPartyCreation(final String name) {
final Party party = this.partyService.createParty(name);
final List<Hero> heroes = IntStream.range(0, 3)
.mapToObj(i -> this.heroService.createHero(String.format("Hero %d for %s", i, name)))
.collect(Collectors.toList());
party.setMembers(heroes);
return beanFactory.getBean(PartyRepository.class).save(party);
}
}
If the server doesn't start, try accessing/initialising the PartyService and HeroService via beanFactory too.
Although it should work (I successfully tested a similar method in my current project), I still don't think it's a good idea to implement it this way.
It's not a search (even if it returns a new object)
It changes the DB, so this endpoint should be accessed via PUT method.
So I suggest creating a custom controller method instead, and moving the logic into the PartyService class.
Oh, btw. The URL you were looking for is
GET /parties/search/dynamicPartyCreation/

OData (Olingo) "inhibit" endpoint

My question is about what is best way to inhibit an endpoint that is automatically provided by Olingo?
I am playing with a simple app based on Spring boot and using Apache Olingo.On short, this is my servlet registration:
#Configuration
public class CxfServletUtil{
#Bean
public ServletRegistrationBean getODataServletRegistrationBean() {
ServletRegistrationBean odataServletRegistrationBean = new ServletRegistrationBean(new CXFNonSpringJaxrsServlet(), "/user.svc/*");
Map<String, String> initParameters = new HashMap<String, String>();
initParameters.put("javax.ws.rs.Application", "org.apache.olingo.odata2.core.rest.app.ODataApplication");
initParameters.put("org.apache.olingo.odata2.service.factory", "com.olingotest.core.CustomODataJPAServiceFactory");
odataServletRegistrationBean.setInitParameters(initParameters);
return odataServletRegistrationBean;
} ...
where my ODataJPAServiceFactory is
#Component
public class CustomODataJPAServiceFactory extends ODataJPAServiceFactory implements ApplicationContextAware {
private static ApplicationContext context;
private static final String PERSISTENCE_UNIT_NAME = "myPersistenceUnit";
private static final String ENTITY_MANAGER_FACTORY_ID = "entityManagerFactory";
#Override
public ODataJPAContext initializeODataJPAContext()
throws ODataJPARuntimeException {
ODataJPAContext oDataJPAContext = this.getODataJPAContext();
try {
EntityManagerFactory emf = (EntityManagerFactory) context.getBean(ENTITY_MANAGER_FACTORY_ID);
oDataJPAContext.setEntityManagerFactory(emf);
oDataJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
return oDataJPAContext;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
...
My entity is quite simple ...
#Entity
public class User {
#Id
private String id;
#Basic
private String firstName;
#Basic
private String lastName;
....
Olingo is doing its job perfectly and it helps me with the generation of all the endpoints around CRUD operations for my entity.
My question is : how can I "inhibit" some of them? Let's say for example that I don't want to enable the delete my entity.
I could try to use a Filter - but this seems a bit harsh. Are there any other, better ways to solve my problem?
Thanks for the help.
As you have said, you could use a filter, but then you are really coupled with the URI schema used by Olingo. Also, things will become complicated when you have multiple, related entity sets (because you could navigate from one to the other, making the URIs more complex).
There are two things that you can do, depending on what you want to achieve:
If you want to have a fined grained control on what operations are allowed or not, you can create a wrapper for the ODataSingleProcesor and throw ODataExceptions where you want to disallow an operation. You can either always throw exceptions (i.e. completely disabling an operation type) or you can use the URI info parameters to obtain the target entity set and decide if you should throw an exception or call the standard single processor. I have used this approach to create a read-only OData service here (basically, I just created a ODAtaSingleProcessor which delegates some calls to the standard one + overridden a method in the service factory to wrap the standard single processor in my wrapper).
If you want to completely un-expose / ignore a given entity or some properties, then you can use a JPA-EDM mapping model end exclude the desired components. You can find an example of such a mapping here: github. The mapping model is just an XML file which maps the JPA entities / properties to EDM entity type / properties. In order for olingo to pick it up, you can pass the name of the file to the setJPAEdmMappingModel method of the ODataJPAContext in your initialize method.

Transportation layer that support Polymorphism and Generics

I am looking for transportation layer for gwt. I would like to create ajax request using generic method, f.e this is my DAO/service:
public class GenericDao<T extends GenericModel<T>> {
private Logger logger = LoggerFactory.getLogger(this.getClass().getCanonicalName());
#Transient protected Class<T> entityClass;
public GenericDao() {
super();
}
public GenericDao(Class<? extends GenericModel<T>> clazz) {
this.entityClass = (Class<T>) clazz;
}
public T getBy(Long id) {
return JPA.em().find(entityClass, id);
}
public List<GenericModel<T>> get() {
logger.error("trying to get data from db");
return getList();
}
public List<GenericModel<T>> getList() {
return JPA.em().createQuery("FROM " + entityClass.getSimpleName()).getResultList();
}
public void save(GenericModel<T> entityClass) {
JPA.em().getTransaction().begin();
JPA.em().persist(entityClass);
JPA.em().getTransaction().commit();
}
public void update(T entityClass) {
JPA.em().getTransaction().begin();
JPA.em().merge(entityClass);
JPA.em().getTransaction().commit();
}
public void delete(T entityClass) {
JPA.em().getTransaction().begin();
JPA.em().remove(entityClass);
JPA.em().getTransaction().commit();
}
}
GenericModel/Entity:
#MappedSuperclass
public class GenericModel<T extends GenericModel<T>> implements Identifiable, Versionable {
#Transient
protected Class<T> entityClass;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Version
private Integer version;
// setter & getter
#Override
public Long getId() {return id;}
public void setId(Long id) {this.id = id;}
#Override
public Integer getVersion() {return version;}
public void setVersion(Integer version) {this.version = version;}
// constructor
public GenericModel() {
Class<?> obtainedClass = getClass();
Type genericSuperclass = null;
for (;;) {
genericSuperclass = obtainedClass.getGenericSuperclass();
if (genericSuperclass instanceof ParameterizedType) {
break;
}
obtainedClass = obtainedClass.getSuperclass();
}
ParameterizedType genericSuperclass_ = (ParameterizedType) genericSuperclass;
try {
entityClass = ((Class) ((Class) genericSuperclass_
.getActualTypeArguments()[0]));
} catch (ClassCastException e) {
entityClass = guessEntityClassFromTypeParametersClassTypedArgument();
}
}
public GenericModel(Long id) {
this();
this.id = id;
}
}
I am looking for mechanism that will allow me to use this generic service for all models on client side (each db entity have id- so I would like to downloads using ajax all my Entities this way, so I should have only one generic method for that on client side).
I've already checked:
GWT-RPC
RequestFactory
RestyGWT
But none of them support this feature.
I've found here:
https://www.mail-archive.com/google-web-toolkit#googlegroups.com/msg100095.html
information that: gwt-jackson supports generics and polymorphism. Unfortunately I didn't found any working example that. Can someone help, give an example, approved that information?
All entities have id and version parameter. So I would like to have one metod on client side RF that will allow me to get from server(service/dao/whatever) that entity by id- like this: Request getBy(Long id); But unfortunatelly I can't make it work. I like the RF way, so I've tried it first. Generally I don't wonna repeat code for downloading entity/proxy by id.
For better understanding, please look also on:
RequestFactory client-side inheritance of typed class with generics
I'm confused as to why you think RPC can't handle generics - according to your link, it can, but RestyGWT cannot. Granted, none of your JPA references make any sense in GWT, but those would live in a DAO on the server, not in the entity/model class themselves, or at least not in the client version. If you had a RPC method that returned T where <T extends GenericModel<T>>, then you would have serializers for every possible GenericModel<?> subtype, and any/all that are gwt-compatible could be sent over the wire.
Edit from update to question:
Your GenericModel class uses features of Java that cannot work in GWT, such as reflection. This cannot be compiled to GWT, since the compiler relies on removing reflection information to minimize your compiled size - leaving in general reflection information means leaving in details about all classes and members, even ones that it can't statically prove are in use, since some reflection might make use of them.
If there is a way to phrase your model object in a way that just deals with the data at hand, focus on that. Otherwise consider a DTO which is just the data to send over the wire - I'm not sure how you would plan to use the entityClass field on the client, or why that would be important to read from the superclass's generics instead of just using getClass().
RequestFactory will have a hard time dealing with generics - unlike RPC (and possibly RestyGWT) it cannot handle polymorphism the way you want, but will instead only send the fields for the declared type, not any arbitrary subtype. RPC will actually send the instance if it is something that the client can handle.

Upgrading from ParameterizedRowMapper to SingleColumnRowMapper for multiple columns

I'm upgrading a Spring 3 application to Spring 4. My #Repository has ParameterizedRowMapper objects to map the SQL results to objects. But since Spring 4 that interface has been deprecated "in favor of the regular SingleColumnRowMapper". But I use mappers for mapping multiple columns. How am I meant to map multiple columns using SingleColumnRowMapper? Or am I meant to be doing something completely different?
For example, here is the kind of code I have now:
private static final ParameterizedRowMapper<Thing> THING_ENTRY_MAPPER = new ParameterizedRowMapper<Thing>() {
#Override
public Thing mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Thing(rs.getLong(1), rs.getLong(2), rs.getInt(3));
}
};
#Override
public List<Thing> getThings(
ID id, long start, long end) {
final Map<String, Object> params = new HashMap<String, Object>(4);
putIDParams(params, id);
putTimeRangeParams(params, start, end);
return getNamedParameterJdbcTemplate().query(QUERY_THING, params,
THING_ENTRY_MAPPER);
}
How should I be implementing that kind of functionality now?
The Javadoc seems to be wrong. The Spring Framework designers probably intend use of the RowMapper<Thing> interface to replace ParameterizedRowMapper<Thing>. That is, use the base interface.

Resources