use of angularBeans.io.LobWrapper in project AngularBeans by bessemHmidi.
the class AuthenticationService method uploadAvatar.
@FileUpload(path = "/avatar")
public void uploadAvatar(List<Upload> uploads) {
avatar = new LobWrapper(uploads.get(0).getAsByteArray(), this);
client.publish(modelQuery.setProperty("avatar", avatar));
}
use of angularBeans.io.LobWrapper in project AngularBeans by bessemHmidi.
the class AuthenticationService method newAccount.
@Put
public void newAccount(User user) {
virtualClassService.createAccount(user);
user.setPhoto(new LobWrapper(avatar.getData(), user));
}
use of angularBeans.io.LobWrapper in project AngularBeans by bessemHmidi.
the class ByteArrayJsonAdapter method serialize.
@Override
public JsonElement serialize(LobWrapper src, Type typeOfSrc, JsonSerializationContext context) {
LobWrapper lobWrapper = src;
container = lobWrapper.getOwner();
String id = "";
Class clazz = container.getClass();
for (Method m : clazz.getMethods()) {
// TODO to many nested statement
if (CommonUtils.isGetter(m) && m.getReturnType().equals(LobWrapper.class) && !Modifier.isVolatile(m.getModifiers())) {
try {
Call lobSource = new Call(container, m);
if (!cache.getCache().containsValue(lobSource)) {
id = String.valueOf(UUID.randomUUID());
cache.getCache().put(id, lobSource);
} else {
for (String idf : cache.getCache().keySet()) {
Call ls = cache.getCache().get(idf);
if (ls.equals(lobSource)) {
id = idf;
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return new JsonPrimitive("lob/" + id + "?" + Calendar.getInstance().getTimeInMillis());
}
use of angularBeans.io.LobWrapper in project AngularBeans by bessemHmidi.
the class ByteArrayJsonAdapter method initJsonSerialiser.
public void initJsonSerialiser() {
GsonBuilder builder = new GsonBuilder().serializeNulls();
builder.setExclusionStrategies(NGConfiguration.getGsonExclusionStrategy());
builder.registerTypeAdapter(LobWrapper.class, new LobWrapperJsonAdapter(cache));
builder.registerTypeAdapter(byte[].class, new ByteArrayJsonAdapter(cache, contextPath));
builder.registerTypeAdapter(LobWrapper.class, new JsonDeserializer<LobWrapper>() {
@Override
public LobWrapper deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
return null;
}
});
if (NGConfiguration.getProperty("DATE_PATTERN") != null) {
final SimpleDateFormat dateFormat = new SimpleDateFormat(NGConfiguration.getProperty("DATE_PATTERN"));
if (dateFormat != null && NGConfiguration.getProperty("TIME_ZONE") != null) {
dateFormat.setTimeZone(TimeZone.getTimeZone(NGConfiguration.getProperty("TIME_ZONE")));
}
builder.registerTypeAdapter(java.sql.Date.class, new JsonSerializer<java.sql.Date>() {
@Override
public JsonElement serialize(java.sql.Date src, Type typeOfSrc, JsonSerializationContext context) {
if (src != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(src);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return new JsonPrimitive(dateFormat.format(cal.getTime()));
}
return null;
}
});
builder.registerTypeAdapter(java.sql.Date.class, new JsonDeserializer<java.sql.Date>() {
@Override
public java.sql.Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
try {
Calendar cal = Calendar.getInstance();
cal.setTime(dateFormat.parse(json.getAsString()));
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return new java.sql.Date(cal.getTime().getTime());
} catch (Exception e) {
}
return null;
}
});
builder.registerTypeAdapter(java.sql.Time.class, new JsonSerializer<java.sql.Time>() {
@Override
public JsonElement serialize(java.sql.Time src, Type typeOfSrc, JsonSerializationContext context) {
if (src != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(src);
return new JsonPrimitive(dateFormat.format(cal.getTime()));
}
return null;
}
});
builder.registerTypeAdapter(java.sql.Time.class, new JsonDeserializer<java.sql.Time>() {
@Override
public java.sql.Time deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
try {
Calendar cal = Calendar.getInstance();
cal.setTime(dateFormat.parse(json.getAsString()));
return new java.sql.Time(cal.getTime().getTime());
} catch (Exception e) {
}
return null;
}
});
builder.registerTypeAdapter(java.sql.Timestamp.class, new JsonSerializer<java.sql.Timestamp>() {
@Override
public JsonElement serialize(java.sql.Timestamp src, Type typeOfSrc, JsonSerializationContext context) {
if (src != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(src);
return new JsonPrimitive(dateFormat.format(cal.getTime()));
}
return null;
}
});
builder.registerTypeAdapter(java.sql.Timestamp.class, new JsonDeserializer<java.sql.Timestamp>() {
@Override
public java.sql.Timestamp deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
try {
Calendar cal = Calendar.getInstance();
cal.setTime(dateFormat.parse(json.getAsString()));
return new java.sql.Timestamp(cal.getTime().getTime());
} catch (Exception e) {
}
return null;
}
});
builder.registerTypeAdapter(java.util.Date.class, new JsonSerializer<java.util.Date>() {
@Override
public JsonElement serialize(java.util.Date src, Type typeOfSrc, JsonSerializationContext context) {
return src == null ? null : new JsonPrimitive(dateFormat.format(src));
}
});
builder.registerTypeAdapter(java.util.Date.class, new JsonDeserializer<java.util.Date>() {
@Override
public java.util.Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
try {
return dateFormat.parse(json.getAsString());
} catch (Exception e) {
}
return null;
}
});
}
mainSerializer = builder.create();
}
Aggregations