diff --git a/jasamedika-business/src/main/java/com/jasamedika/medifirst2000/service/ModelService.java b/jasamedika-business/src/main/java/com/jasamedika/medifirst2000/service/ModelService.java index 953e7b0c..f7116e3e 100644 --- a/jasamedika-business/src/main/java/com/jasamedika/medifirst2000/service/ModelService.java +++ b/jasamedika-business/src/main/java/com/jasamedika/medifirst2000/service/ModelService.java @@ -3,11 +3,7 @@ package com.jasamedika.medifirst2000.service; import java.util.List; import java.util.Map; - -import com.jasamedika.medifirst2000.entities.Pasien; import com.jasamedika.medifirst2000.vo.ModelVO; -import com.jasamedika.medifirst2000.vo.ModelVO; -import com.jasamedika.medifirst2000.vo.PasienVO; /** * Pasien Service diff --git a/jasamedika-business/src/main/java/com/jasamedika/medifirst2000/service/impl/ModelServiceImpl.java b/jasamedika-business/src/main/java/com/jasamedika/medifirst2000/service/impl/ModelServiceImpl.java index af37fdb8..70e8aaec 100644 --- a/jasamedika-business/src/main/java/com/jasamedika/medifirst2000/service/impl/ModelServiceImpl.java +++ b/jasamedika-business/src/main/java/com/jasamedika/medifirst2000/service/impl/ModelServiceImpl.java @@ -9,7 +9,6 @@ import java.util.Map; import org.hibernate.validator.constraints.Length; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.MessageSource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -34,18 +33,22 @@ import com.jasamedika.medifirst2000.vo.ModelVO; */ @Service public class ModelServiceImpl implements ModelService { + @Autowired private GenericServDao genericServDao; - - @Autowired - private MessageSource messageSource; - // get /convert string name from org.hibernate.validator.constraints.Length - // to length + /** + * get /convert string name from org.hibernate.validator.constraints.Length + * to length + * + * @param value + * @return + */ public String getName(String value) { return value.substring(value.lastIndexOf('.') + 1).trim(); } + @SuppressWarnings("rawtypes") public Object converToObject(String value) { String name = "com.jasamedika.medifirst2000.vo." + value; Class cl = null; @@ -64,13 +67,10 @@ public class ModelServiceImpl implements ModelService { return o; } + @SuppressWarnings("rawtypes") public static List GetFields(Class data) { List items = new ArrayList(); - String name = data.getName(); Class parent = data.getSuperclass(); - if (parent instanceof Class) { - name = ((Class) parent).getName(); - } Class tmpClass = null; if (BaseModelVO.class.isAssignableFrom(data.getClass())) { @@ -98,86 +98,87 @@ public class ModelServiceImpl implements ModelService { return items; } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "serial" }) @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) @Override - public ModelVO getModelSerializeEntity(String name,String language) { + public ModelVO getModelSerializeEntity(String name, String language) { ModelVO modelDTO = new ModelVO(); - List> allAttributes = new ArrayList>(); + List> allAttributes = new ArrayList>(); Object o = converToObject(name); Map model = new HashMap(); for (Object field : GetFields(o.getClass()).toArray()) { - if (field instanceof Field){ + if (field instanceof Field) { - String[] fieldsToInclude = { "String", "Integer", "int","byte","short","Boolean","Byte","Date","Double","double","long","Long","Float","float"}; + String[] fieldsToInclude = { "String", "Integer", "int", "byte", "short", "Boolean", "Byte", "Date", + "Double", "double", "long", "Long", "Float", "float" }; boolean found = false; for (String element : fieldsToInclude) { - if (getName(((Field) field).getType().toString()).equals(element)) { - found = true; - break; - } + if (getName(((Field) field).getType().toString()).equals(element)) { + found = true; + break; + } } if (!found) { - + if (getName(((Field) field).getType().toString()).equals("Set")) { model.put(((Field) field).getName(), new ArrayList()); - }else{ + } else { model.put(((Field) field).getName(), new BaseModel() { }); } - - }else{ + + } else { model.put(((Field) field).getName(), ""); } - Annotation[] as = ((Field) field).getDeclaredAnnotations(); - - if(CommonUtil.isNotNullOrEmpty(as)){ - for (Annotation a : as) { - if (a instanceof javax.persistence.ManyToOne) { - Map modelChild = new HashMap(); - for (Object fieldChild : GetFields(converToObject(getName(((Field) field).getType().toString())).getClass()).toArray()) { - boolean foundChild = false; - for (String element : fieldsToInclude) { - if (getName(((Field) fieldChild).getType().toString()).equals(element)) { - foundChild = true; - break; - } - } - if (!foundChild) { - - if (getName(((Field) fieldChild).getType().toString()).equals("Set")) { - modelChild.put(((Field) fieldChild).getName(), new ArrayList()); - }else{ - modelChild.put(((Field) fieldChild).getName(), new BaseModel() { - }); - } - - }else{ - modelChild.put(((Field) fieldChild).getName(), ""); - } + Annotation[] as = ((Field) field).getDeclaredAnnotations(); - + if (CommonUtil.isNotNullOrEmpty(as)) { + for (Annotation a : as) { + if (a instanceof javax.persistence.ManyToOne) { + Map modelChild = new HashMap(); + for (Object fieldChild : GetFields( + converToObject(getName(((Field) field).getType().toString())).getClass()) + .toArray()) { + boolean foundChild = false; + for (String element : fieldsToInclude) { + if (getName(((Field) fieldChild).getType().toString()).equals(element)) { + foundChild = true; + break; + } + } + if (!foundChild) { + + if (getName(((Field) fieldChild).getType().toString()).equals("Set")) { + modelChild.put(((Field) fieldChild).getName(), new ArrayList()); + } else { + modelChild.put(((Field) fieldChild).getName(), new BaseModel() { + }); + } + + } else { + modelChild.put(((Field) fieldChild).getName(), ""); + } + + } + List> attribtues = listMapAttributes( + converToObject(getName(((Field) field).getType().toString())), + ((Field) field).getName(), language); + for (Map map : attribtues) { + allAttributes.add(map); + } + model.put(((Field) field).getName(), modelChild); } - List> attribtues =listMapAttributes(converToObject(getName(((Field) field).getType().toString())),((Field) field).getName(),language); - for(Map map : attribtues) - { - allAttributes.add(map); - } - //modelChild.put("attributes", listMapAttributes(converToObject(getName(((Field) field).getType().toString())))); - model.put(((Field) field).getName(), modelChild); + } } - - } } } modelDTO.setModel(model); - for(Map map : listMapAttributes(o,"",language)) - { + for (Map map : listMapAttributes(o, "", language)) { allAttributes.add(map); } modelDTO.setAttributes(allAttributes); @@ -185,35 +186,32 @@ public class ModelServiceImpl implements ModelService { } - - - - //generate attribute json - public List>listMapAttributes(Object object,String modelName,String language){ + // generate attribute json + public List> listMapAttributes(Object object, String modelName, String language) { List> attributeModelList = new ArrayList>(); for (Object field : GetFields(object.getClass()).toArray()) { if (field instanceof Field) { Map attributeModel = new HashMap(); - if(modelName != "") - attributeModel.put("name",modelName+"."+ ((Field) field).getName()); + if (modelName != "") + attributeModel.put("name", modelName + "." + ((Field) field).getName()); else attributeModel.put("name", ((Field) field).getName()); attributeModel.put("type", getName(((Field) field).getType().getName())); Annotation[] as = ((Field) field).getDeclaredAnnotations(); - + for (Annotation a : as) { - checkObject(a, attributeModel,language); + checkObject(a, attributeModel, language); } attributeModelList.add(attributeModel); } } return attributeModelList; } - - public Map checkObject(Annotation a,Map attributeModel, String language){ + + public Map checkObject(Annotation a, Map attributeModel, String language) { if (a instanceof org.hibernate.validator.constraints.Length) { org.hibernate.validator.constraints.Length length = (Length) a; attributeModel.put("maxlength", length.max()); @@ -238,24 +236,19 @@ public class ModelServiceImpl implements ModelService { if (a instanceof com.jasamedika.medifirst2000.helper.Caption) { com.jasamedika.medifirst2000.helper.Caption test = (Caption) a; System.out.println(test.value()); - //attributeModel.put("caption", messageSource.getMessage(test.value(), null, new Locale(language))); - attributeModel.put("caption",test.value()); + attributeModel.put("caption", test.value()); } - + return attributeModel; - - - - } - public List> getAllData(String entity, String field, Integer take, Integer skip, Integer page, + public List> getAllData(String entity, String field, Integer take, Integer skip, Integer page, Integer pageSize, String logic, String value, String fieldS, String operator, String ignorecase, String criteria, String values) { int rowStart = 0; int rowEnd = 0; - if(take!=null) - rowEnd=take; + if (take != null) + rowEnd = take; if (take != null && skip != null && page != null && pageSize != null) { int totalRow = genericServDao.dataCount(entity, value, fieldS, criteria, values); int totalPages = 0; @@ -273,15 +266,14 @@ public class ModelServiceImpl implements ModelService { rowStart = (pageRequested * pageSize) - pageSize; rowEnd = take; } - List> listEntity =null; + List> listEntity = null; try { - listEntity = JsonUtil.ToMaps( genericServDao.getDatas(entity, field, Math.abs(rowStart), rowEnd, logic, value, fieldS, - operator,criteria,values)); + listEntity = JsonUtil.ToMaps(genericServDao.getDatas(entity, field, Math.abs(rowStart), rowEnd, logic, + value, fieldS, operator, criteria, values)); } catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } return listEntity; } - } diff --git a/jasamedika-core/src/main/java/com/jasamedika/medifirst2000/base/BaseModel.java b/jasamedika-core/src/main/java/com/jasamedika/medifirst2000/base/BaseModel.java index a0b1045d..c92a27f6 100644 --- a/jasamedika-core/src/main/java/com/jasamedika/medifirst2000/base/BaseModel.java +++ b/jasamedika-core/src/main/java/com/jasamedika/medifirst2000/base/BaseModel.java @@ -25,9 +25,10 @@ import com.jasamedika.medifirst2000.util.JsonUtil; * * @author Adik */ +@SuppressWarnings("serial") @MappedSuperclass public abstract class BaseModel implements Serializable { - + public Map ToSingleMap() throws IllegalArgumentException, IllegalAccessException { Map maps = new HashMap(); for (Field field : BaseModel.GetFields(this.getClass())) { @@ -38,9 +39,9 @@ public abstract class BaseModel implements Serializable { if (name.equals("_methods_")) continue; if (name.equals("handler")) - continue; + continue; if (name.equals("_filter_signature")) - continue; + continue; Boolean valid = false; for (java.lang.annotation.Annotation annotation : field.getDeclaredAnnotations()) { if (annotation instanceof JoinColumn) { @@ -62,9 +63,11 @@ public abstract class BaseModel implements Serializable { } return maps; } + public Map ToMap() throws IllegalArgumentException, IllegalAccessException { return ToMap(3); } + public Map ToMap(Integer index) throws IllegalArgumentException, IllegalAccessException { Map maps = new HashMap(); for (Field field : BaseModel.GetFields(this.getClass())) { @@ -75,9 +78,9 @@ public abstract class BaseModel implements Serializable { if (name.equals("_methods_")) continue; if (name.equals("handler")) - continue; + continue; if (name.equals("_filter_signature")) - continue; + continue; Boolean valid = false; for (java.lang.annotation.Annotation annotation : field.getDeclaredAnnotations()) { if (annotation instanceof JoinColumn) { @@ -93,93 +96,91 @@ public abstract class BaseModel implements Serializable { } } - if (valid == false && field.get(this)!=null) + if (valid == false && field.get(this) != null) maps.put(field.getName(), field.get(this)); } - if(index>1) - for (Field field : BaseModel.GetFields(this.getClass())) { - String str = field.getName(); - String name = field.getName(); - field.setAccessible(true); - if (name.equals("serialVersionUID")) - continue; - if (name.equals("_methods_")) - continue; - if (name.equals("handler")) - continue; - if (name.equals("_filter_signature")) + if (index > 1) + for (Field field : BaseModel.GetFields(this.getClass())) { + String str = field.getName(); + String name = field.getName(); + field.setAccessible(true); + if (name.equals("serialVersionUID")) continue; - Boolean valid = false; - for (java.lang.annotation.Annotation annotation : field.getDeclaredAnnotations()) { - if (annotation instanceof JoinColumn) { - valid = true; - } else if (annotation instanceof Column) { - Column column = (Column) annotation; - if (column.name().endsWith("Fk")) - if (field.getName().endsWith("Id") == false) - valid = true; - } else if (annotation instanceof OneToMany) { + if (name.equals("_methods_")) + continue; + if (name.equals("handler")) + continue; + if (name.equals("_filter_signature")) + continue; + Boolean valid = false; + for (java.lang.annotation.Annotation annotation : field.getDeclaredAnnotations()) { + if (annotation instanceof JoinColumn) { + valid = true; + } else if (annotation instanceof Column) { + Column column = (Column) annotation; + if (column.name().endsWith("Fk")) + if (field.getName().endsWith("Id") == false) + valid = true; + } else if (annotation instanceof OneToMany) { - valid = true; - } - if (valid == true) { - Object property = field.get(this); + valid = true; + } + if (valid == true) { + Object property = field.get(this); - if (property == null) - { - //maps.put(str, null); - - } - else { - - if(property instanceof HibernateProxy) - { - property = JsonUtil.initializeAndUnproxy(property); - } - if (property instanceof BaseModel) { - Map mapItems = new HashMap(); - for (Field fieldItem : BaseModel.GetFields(property.getClass())) { - String nameItem = fieldItem.getName(); - fieldItem.setAccessible(true); - if (nameItem.equals("serialVersionUID")) - continue; - if (nameItem.equals("_methods_")) - continue; - if (nameItem.equals("handler")) - continue; - if (nameItem.equals("_filter_signature")) + if (property == null) { + // do when property is null + } else { + + if (property instanceof HibernateProxy) { + property = JsonUtil.initializeAndUnproxy(property); + } + if (property instanceof BaseModel) { + Map mapItems = new HashMap(); + for (Field fieldItem : BaseModel.GetFields(property.getClass())) { + String nameItem = fieldItem.getName(); + fieldItem.setAccessible(true); + if (nameItem.equals("serialVersionUID")) continue; - Boolean validItem = false; - for (java.lang.annotation.Annotation annotationItem : fieldItem - .getDeclaredAnnotations()) { - if (annotationItem instanceof JoinColumn) { - validItem = true; - } else if (annotationItem instanceof Column) { - Column columnItem = (Column) annotationItem; - if (columnItem.name().endsWith("Fk")) - if (fieldItem.getName().endsWith("Id") == false) - validItem = true; - } else if (annotationItem instanceof OneToMany) { + if (nameItem.equals("_methods_")) + continue; + if (nameItem.equals("handler")) + continue; + if (nameItem.equals("_filter_signature")) + continue; + Boolean validItem = false; + for (java.lang.annotation.Annotation annotationItem : fieldItem + .getDeclaredAnnotations()) { + if (annotationItem instanceof JoinColumn) { + validItem = true; + } else if (annotationItem instanceof Column) { + Column columnItem = (Column) annotationItem; + if (columnItem.name().endsWith("Fk")) + if (fieldItem.getName().endsWith("Id") == false) + validItem = true; + } else if (annotationItem instanceof OneToMany) { - validItem = true; + validItem = true; + } + } + if (validItem == false && fieldItem.get(property) != null) { + mapItems.put(fieldItem.getName(), fieldItem.get(property)); } } - if (validItem == false && fieldItem.get(property)!=null) { - mapItems.put(fieldItem.getName(), fieldItem.get(property)); - } + maps.put(str, mapItems); } - maps.put(str, mapItems); + } } - } } - } return maps; } + + @SuppressWarnings("rawtypes") public static List GetFields(Class data) { List items = new ArrayList(); Class parent = data.getSuperclass(); @@ -213,6 +214,8 @@ public abstract class BaseModel implements Serializable { public String getName(String value) { return value.substring(value.lastIndexOf('.') + 1).trim(); } + + @SuppressWarnings("rawtypes") public Map serialize(String[] fieldsToInclude, String className) throws Exception { String name = "com.jasamedika.medifirst2000.entities." + getName(className); Class cl = null; @@ -222,18 +225,18 @@ public abstract class BaseModel implements Serializable { e.printStackTrace(); } Map fields = new HashMap(); - if(CommonUtil.isNotNullOrEmpty(cl)){ + if (CommonUtil.isNotNullOrEmpty(cl)) { for (Object f : GetFields(cl).toArray()) { - + if (!getName(((Field) f).getType().toString()).equalsIgnoreCase("Set")) { if (f instanceof Field) { ((AccessibleObject) f).setAccessible(true); boolean found = false; if (CommonUtil.isNotNullOrEmpty(fieldsToInclude)) { for (String element : fieldsToInclude) { - if (((Field) f).getName().equals(element)){ + if (((Field) f).getName().equals(element)) { found = true; - break; + break; } } } else { @@ -247,10 +250,8 @@ public abstract class BaseModel implements Serializable { } } } - return fields; } - } diff --git a/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/controller/GenericServiceController.java b/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/controller/GenericServiceController.java index d75fd073..c2e3b5d9 100644 --- a/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/controller/GenericServiceController.java +++ b/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/controller/GenericServiceController.java @@ -40,14 +40,10 @@ public class GenericServiceController extends LocaleController modelService; private static final String CONTENT_TYPE = "Content-Type"; + @SuppressWarnings("rawtypes") public static List GetFields(Class data) { List items = new ArrayList(); - // String name = data.getName(); Class parent = data.getSuperclass(); - // if (parent instanceof Class) { - // name = ((Class) parent).getName(); - // } - Class tmpClass = null; if (BaseModelVO.class.isAssignableFrom(data.getClass())) { tmpClass = BaseTransactionVO.class; @@ -80,14 +76,7 @@ public class GenericServiceController extends LocaleController>> listGeneric( @RequestParam(value = "view", required = false) String entity, @RequestParam(value = "select", required = false) String field, @@ -103,7 +92,6 @@ public class GenericServiceController extends LocaleController> modelGenericVO = modelService.getAllData(entity, field, take, skip, page, pageSize, logic, value, fieldS, operator, ignorecase, criteria, values); HttpHeaders headers = new HttpHeaders(); - - // headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); -// Map map = new HashMap(); try { - return new ResponseEntity(JsonUtil.ToMaps(modelGenericVO), headers, HttpStatus.OK); + return new ResponseEntity>>(JsonUtil.ToMaps(modelGenericVO), headers, + HttpStatus.OK); } catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } - // return RestUtil.getJsonResponse(modelGenericVO, HttpStatus.OK); + return null; } diff --git a/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/controller/base/LocaleController.java b/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/controller/base/LocaleController.java index 876919d6..943235fa 100644 --- a/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/controller/base/LocaleController.java +++ b/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/controller/base/LocaleController.java @@ -41,7 +41,6 @@ import com.jasamedika.medifirst2000.converter.BaseConverterImpl; import com.jasamedika.medifirst2000.core.web.WebConstants; import com.jasamedika.medifirst2000.entities.Pegawai; import com.jasamedika.medifirst2000.service.ActivityPegawaiService; -import com.jasamedika.medifirst2000.service.AgamaService; import com.jasamedika.medifirst2000.service.LoginUserService; import com.jasamedika.medifirst2000.service.ModelService; import com.jasamedika.medifirst2000.util.rest.RestUtil; @@ -58,30 +57,27 @@ import io.socket.client.IO; * @author Roberto */ public abstract class LocaleController { + /* * messageSource bean injected for each controller for accessing message * source */ - @Autowired private ActivityPegawaiService activityPegawaiServiceImpl; - - + @Autowired private BaseConverterImpl pegawaiConverter; - + @Autowired private LoginUserService loginUserService; - + @Autowired private MessageSource messageSource; + @SuppressWarnings("rawtypes") @Autowired private ModelService modelService; - - @Autowired - private AgamaService agamaService; protected Map mapHeaderMessage = new HashMap(); /* @@ -90,64 +86,62 @@ public abstract class LocaleController { protected String getMessage(String code, HttpServletRequest request) { return messageSource.getMessage(code, null, new Locale(getCoociesLanguage(request))); } - - protected void SaveLog(String keterangan,String group, HttpServletRequest request) { - activityPegawaiServiceImpl.record(pegawaiConverter.transferModelToVO(loginUserService.getLoginUser().getPegawai(), new PegawaiVO()) , new Date(), keterangan,group); + + protected void SaveLog(String keterangan, String group, HttpServletRequest request) { + activityPegawaiServiceImpl.record( + pegawaiConverter.transferModelToVO(loginUserService.getLoginUser().getPegawai(), new PegawaiVO()), + new Date(), keterangan, group); } - protected Object getItem(HttpServletRequest request,Object vo) - { + + protected Object getItem(HttpServletRequest request, Object vo) { BufferedReader reader; String read = null; String resultData = ""; Gson gson = new Gson(); try { reader = new BufferedReader(new InputStreamReader(request.getInputStream())); - - - while ((read = reader.readLine()) != null) { - resultData += read; - System.out.println(read); - } - - gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")//.excludeFieldsWithoutExposeAnnotation() - .create(); + while ((read = reader.readLine()) != null) { + resultData += read; + System.out.println(read); + } + + gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); } catch (IOException e) { e.printStackTrace(); } - return vo= gson.fromJson(resultData, vo.getClass()); + return vo = gson.fromJson(resultData, vo.getClass()); } - protected Object getItem2(HttpServletRequest request,Object vo) - { + protected Object getItem2(HttpServletRequest request, Object vo) { BufferedReader reader; String read = null; String resultData = ""; Gson gson = new Gson(); try { reader = new BufferedReader(new InputStreamReader(request.getInputStream())); - + while ((read = reader.readLine()) != null) { resultData += read; System.out.println(read); } GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer() { - @Override - public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { - if(json.getAsString() instanceof String){ - return new Date(); - }else{ - return new Date(json.getAsJsonPrimitive().getAsLong()); - } - } - }); + gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer() { + @Override + public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + if (json.getAsString() instanceof String) { + return new Date(); + } else { + return new Date(json.getAsJsonPrimitive().getAsLong()); + } + } + }); gson = gsonBuilder.create(); } catch (IOException e) { e.printStackTrace(); } - return vo= gson.fromJson(resultData, vo.getClass()); + return vo = gson.fromJson(resultData, vo.getClass()); } @RequestMapping(value = "/lang/{lang}", method = RequestMethod.GET) @@ -244,33 +238,26 @@ public abstract class LocaleController { } } -// @PersistenceContext -// protected EntityManager em; - public String GetSettingDataFixed(String prefix) { return activityPegawaiServiceImpl.GetSettingDataFixed(prefix); -// StringBuffer buffer = new StringBuffer(); -// buffer.append("select model.nilaiField from SettingDataFixed ") -// .append(" model where model.namaField ='" + prefix + "' "); -// Query query = em.createQuery(buffer.toString()); -// -// return (String) query.getSingleResult(); } + protected void BroadcastMessage(final String to, final Object data) { final io.socket.client.Socket socket; - try { - String url =GetSettingDataFixed("UrlSocketMessaging"); + try { + String url = GetSettingDataFixed("UrlSocketMessaging"); socket = IO.socket(url); socket.on(io.socket.client.Socket.EVENT_CONNECT, new io.socket.emitter.Emitter.Listener() { @Override public void call(Object... args) { - + try { Gson gson = new Gson(); String json = gson.toJson(data); - JSONObject item= new JSONObject("{\"to\":\""+to+"\",\"message\":\""+json.replace("\"", "'")+"\"}"); + JSONObject item = new JSONObject( + "{\"to\":\"" + to + "\",\"message\":\"" + json.replace("\"", "'") + "\"}"); socket.emit("subscribe", item); } catch (JSONException e) { e.printStackTrace(); @@ -283,6 +270,7 @@ public abstract class LocaleController { e.printStackTrace(); } } + protected void BroadcastMessage(final String to, final String data) { final io.socket.client.Socket socket; try { @@ -292,9 +280,9 @@ public abstract class LocaleController { @Override public void call(Object... args) { - + try { - JSONObject item= new JSONObject("{\"to\":\""+to+"\",\"message\":\""+data+"\"}"); + JSONObject item = new JSONObject("{\"to\":\"" + to + "\",\"message\":\"" + data + "\"}"); socket.emit("subscribe", item); } catch (JSONException e) { e.printStackTrace(); @@ -307,10 +295,10 @@ public abstract class LocaleController { e.printStackTrace(); } } - + protected void BroadcastMessageOther(final String to, final Object data) { final io.socket.client.Socket socket; - try { + try { String url = GetSettingDataFixed("UrlSocketMessaging"); socket = IO.socket(url); @@ -322,7 +310,7 @@ public abstract class LocaleController { Map result = new HashMap<>(); result.put("message", data); result.put("to", to); - + Gson gson = new Gson(); JSONObject item = new JSONObject(gson.toJson(result)); socket.emit("subscribe", item);