use of org.summerb.utils.DtoBase in project summerb by skarpushin.
the class EntityChangedEventAdapter method resolveParametersClass.
@SuppressWarnings("unchecked")
protected <T extends DtoBase> Class<T> resolveParametersClass(JsonObject jsonObject) {
JsonPrimitive prim = (JsonPrimitive) jsonObject.get(CLASSNAME);
if (prim == null) {
throw new IllegalArgumentException("JSON Parse error: didn't find classname field named '" + CLASSNAME + "' in object: " + jsonObject);
}
String className = prim.getAsString();
Class<T> klass = null;
try {
klass = (Class<T>) Class.forName(className);
if (!DtoBase.class.isAssignableFrom(klass)) {
throw new IllegalArgumentException("Potentially security breach. Attempt to Class.forName: " + className);
}
} catch (ClassNotFoundException e) {
// log.error("Failed to resolve class: " + className, e);
throw new JsonParseException(e.getMessage());
}
return klass;
}
use of org.summerb.utils.DtoBase in project summerb by skarpushin.
the class EntityChangedEventAdapter method deserialize.
@SuppressWarnings({ "unchecked", "deprecation" })
@Override
public EntityChangedEvent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
Class<? extends DtoBase> klass = resolveParametersClass(jsonObject);
JsonElement jsonElement = jsonObject.get(INSTANCE);
DtoBase value = context.deserialize(jsonElement, klass);
ChangeType changeType = context.deserialize(jsonObject.get("ct"), ChangeType.class);
return new EntityChangedEvent(value, changeType);
}
use of org.summerb.utils.DtoBase in project summerb by skarpushin.
the class RestExceptionTranslator method doFilter.
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
try {
chain.doFilter(request, response);
log.trace("Chain processed normally");
} catch (Exception ex) {
log.info("Unhandled exception while processing REST query", ex);
DtoBase result = determineFailureResult(ex, request, response);
jsonResponseHelper.writeResponseBody(result, response);
}
}
use of org.summerb.utils.DtoBase in project summerb by skarpushin.
the class EasyCrudScaffoldImpl method discoverDtoClassFromServiceInterface.
@SuppressWarnings("unchecked")
protected <TId, TDto extends HasId<TId>, TService extends EasyCrudService<TId, TDto>> Class<TDto> discoverDtoClassFromServiceInterface(Class<TService> serviceInterface) {
Preconditions.checkArgument(EasyCrudService.class.isAssignableFrom(serviceInterface), "Service interface is supposed to be a subclass of EasyCrudService");
ParameterizedType easyCrudServiceType = null;
for (int i = 0; i < serviceInterface.getGenericInterfaces().length; i++) {
Type candidate = serviceInterface.getGenericInterfaces()[i];
if (!(candidate instanceof ParameterizedType)) {
continue;
}
ParameterizedType candidatePt = (ParameterizedType) candidate;
if (EasyCrudService.class.equals(candidatePt.getRawType())) {
easyCrudServiceType = candidatePt;
break;
}
}
Preconditions.checkState(easyCrudServiceType != null, "Wasn't able to located parent interface EasyCrudService");
Type ret = easyCrudServiceType.getActualTypeArguments()[1];
Preconditions.checkArgument(DtoBase.class.isAssignableFrom((Class<?>) ret), "DTO class supposed to impl DtoBase interface");
Preconditions.checkArgument(HasId.class.isAssignableFrom((Class<?>) ret), "DTO class supposed to impl HasId interface");
return (Class<TDto>) ret;
}
Aggregations