Search in sources :

Example 1 with LobWrapper

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));
}
Also used : LobWrapper(angularBeans.io.LobWrapper) FileUpload(angularBeans.io.FileUpload)

Example 2 with LobWrapper

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));
}
Also used : LobWrapper(angularBeans.io.LobWrapper) Put(angularBeans.api.http.Put)

Example 3 with LobWrapper

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());
}
Also used : Call(angularBeans.io.Call) JsonPrimitive(com.google.gson.JsonPrimitive) LobWrapper(angularBeans.io.LobWrapper) Method(java.lang.reflect.Method)

Example 4 with LobWrapper

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();
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) LobWrapper(angularBeans.io.LobWrapper) JsonDeserializationContext(com.google.gson.JsonDeserializationContext) GsonBuilder(com.google.gson.GsonBuilder) Calendar(java.util.Calendar) Type(java.lang.reflect.Type) JsonElement(com.google.gson.JsonElement) JsonSerializationContext(com.google.gson.JsonSerializationContext) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

LobWrapper (angularBeans.io.LobWrapper)4 JsonPrimitive (com.google.gson.JsonPrimitive)2 Put (angularBeans.api.http.Put)1 Call (angularBeans.io.Call)1 FileUpload (angularBeans.io.FileUpload)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonDeserializationContext (com.google.gson.JsonDeserializationContext)1 JsonElement (com.google.gson.JsonElement)1 JsonSerializationContext (com.google.gson.JsonSerializationContext)1 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1