public void setSleepTime(SleepTime inSleepTime, boolean inUpdateState) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); Factories.OBJECT_SLEEP.setObjectSleepTime(this, inSleepTime); if (inUpdateState) { // calcul s'il est en veille ou pas final boolean isSleeping = ObjectSleep.ObjectSleepCommon.asleep(this); if (isXMPP()) { final List<String> resources = getResources(); // IQResourcesQuery.getClientResources(getXmppAddress()); if (isSleeping) { if (!resources.contains("asleep")) { sendXmppStatus(Message.MODE_VEILLE, JabberMessageFactory.IQ_STATUS_IDLE_MODE); } else { setObject_state(theUpdateMap, VObject.STATUS_VEILLE); } } else { if (resources.contains("asleep")) { sendXmppStatus(Message.MODE.ACTIF.getId(), JabberMessageFactory.IQ_STATUS_ASLEEP_MODE); } else { setObject_state(theUpdateMap, VObject.STATUS_ACTIF); } } } else { setObject_state(theUpdateMap, (isSleeping ? VObject.STATUS_VEILLE : VObject.STATUS_ACTIF)); } } update(theUpdateMap); }
/** * Vérifie s'il n'y a pas de mauvais caratère dans le jid * * @param inValue (dans notre cas la serial) * @return true si ok */ public static boolean checkJid(String inValue) { return (inValue != null) && !VObjectImpl.JID_REGEX.matcher(inValue).find(); } public String getXmppAddress() { // Le domaine dépend du hardware. final String theDomain = Hardware.HARDWARE.MIRROR.is(this) ? Constantes.XMPP_MIRROR_DOMAIN : Constantes.XMPP_NABAZTAG_DOMAIN; String inSerial = getObject_serial().toLowerCase(); if (!VObjectImpl.checkJid(inSerial)) { inSerial = "invalid"; VObjectImpl.LOGGER.fatal("Invalid Serial in Object:" + inSerial); } String theUser; if (HARDWARE.MIRROR.is(this)) { theUser = VObjectImpl.makeMirrorXmppUser(inSerial); } else { theUser = inSerial; } return theUser + "@" + theDomain; } // public Map<VAction, List<ObjectHasReadContent>> getContents() { // if (this.objectHasReadContent == null) { // try { // this.objectHasReadContent = // MultipleDecoratedAssociation.createMultipleDecoratedAssociation(this, // VActionImpl.SPECIFICATION, StringShop.ACTION_ID, ObjectHasReadContentImpl.SPECIFICATION, // "object_id"); // } catch (final SQLException e) { // VObjectImpl.LOGGER.fatal(e, e); // } // } // return this.objectHasReadContent; // } public static String makeMirrorXmppUser(String inSerial) { // encode the mac address as described in the VioletOS Specification // 11.1.2. // TODO this is quite heavy computation, it should be done only once // TODO the code should maybe be moved somewhere else, in a special // Mir:ror class ? String theUser; try { final String theSecretKey = "423bef3588d1328b571584e4f7d29d46"; final byte[] hash = MessageDigest.getInstance("MD5").digest((inSerial + theSecretKey).getBytes()); // get the first 4 characters of the hash to a string final StringBuilder hashString = new StringBuilder(); for (int i = 0; i < 2; ++i) { final String hex = Integer.toHexString(hash[i]); if (hex.length() == 1) { hashString.append('0'); hashString.append(hex.charAt(hex.length() - 1)); } else { hashString.append(hex.substring(hex.length() - 2)); } } theUser = inSerial + hashString; } catch (final NoSuchAlgorithmException e) { VObjectImpl.LOGGER.fatal( "Could not get a MD5 MessageDigest. Can't compute xmpp address of a mir:ror."); theUser = inSerial; } return theUser; } public long getObject_creation() { return this.object_creation; } public int getObject_delay() { return this.object_delay; } public HARDWARE getHardware() { return HARDWARE.findById(this.mHardware.get(this.object_hardware).getId()); } public int getObject_left() { return this.object_left; } public ObjectProfile getProfile() { return this.mProfile.get(this.object_id); } public void setLeftAndRight(int inLeft, int inRight) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setObject_left(theUpdateMap, inLeft); setObject_right(theUpdateMap, inRight); update(theUpdateMap); } private void setObject_left(Map<String, Object> inUpdateMap, int inValue) { if (this.object_left != inValue) { this.object_left = inValue; inUpdateMap.put("object_left", inValue); } } private void setObject_right(Map<String, Object> inUpdateMap, int inValue) { if (this.object_right != inValue) { this.object_right = inValue; inUpdateMap.put("object_right", inValue); } } public String getObject_loc() { return this.object_loc; } public String getObject_login() { return this.object_login; } private void setObject_login(Map<String, Object> inUpdateMap, String inValue) { if (!this.object_login.equals(inValue)) { final UserPwd thePwd = UserPwdImpl.findByPseudoAndUser(this.object_login, getOwner()); if (thePwd != null) { final String thePassword = thePwd.getPwd(); thePwd.delete(); try { new UserPwdImpl(getOwner().getId(), inValue, thePassword, false); } catch (final SQLException e) { VObjectImpl.LOGGER.fatal(e, e); } } this.object_login = inValue; inUpdateMap.put("object_login", this.object_login); } } private void setObject_serial(Map<String, Object> inUpdateMap, String inValue) { if (this.object_serial != inValue) { this.object_serial = inValue; inUpdateMap.put("object_serial", inValue); } } public void setLogin(String inLogin) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setObject_login(theUpdateMap, inLogin); update(theUpdateMap); updateKey("object_login"); } public int getObject_mode() { return this.object_mode; } private void setObject_mode(Map<String, Object> inUpdateMap, int object_mode) { if (this.object_mode != object_mode) { this.object_mode = object_mode; inUpdateMap.put("object_mode", object_mode); } } public void setMode(int inMode) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setObject_mode(theUpdateMap, inMode); update(theUpdateMap); } private void setLastActivityTime(Map<String, Object> inUpdateMap, long time) { if (time > this.object_lastping + VObjectImpl.TIME_TO_UPDATE_LAST_ACTIVITY) { this.object_lastping = time; inUpdateMap.put("object_lastping", this.object_lastping); } } public void setLastActivityTime() { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setLastActivityTime(theUpdateMap, System.currentTimeMillis() / 1000); update(theUpdateMap); } public int getObject_n1() { return this.object_n1; } public int getObject_n2() { return this.object_n2; } public int getObject_nbmsg() { return this.object_nbmsg; } public void setPingCache(int inFirstEventID, int inSecondEventID) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setObject_n1(theUpdateMap, inFirstEventID); setObject_n2(theUpdateMap, inSecondEventID); update(theUpdateMap); } public void clearPingCache() { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setObject_n1(theUpdateMap, 0); update(theUpdateMap); } private void setObject_n1(Map<String, Object> inUpdateMap, int inValue) { if (this.object_n1 != inValue) { this.object_n1 = inValue; inUpdateMap.put("object_n1", inValue); } } private void setObject_n2(Map<String, Object> inUpdateMap, int inValue) { if (this.object_n2 != inValue) { this.object_n2 = inValue; inUpdateMap.put("object_n2", inValue); } } private void setObject_nbmsg(Map<String, Object> inUpdateMap, int inValue) { if (this.object_nbmsg != inValue) { this.object_nbmsg = inValue; inUpdateMap.put("object_nbmsg", inValue); } } // Use for Ping Object public void setNbMsg(int inNbMessage) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setObject_nbmsg(theUpdateMap, inNbMessage); update(theUpdateMap); } public User getOwner() { return this.mOwner.get(this.object_owner); } public int getObject_right() { return this.object_right; } public String getObject_serial() { return this.object_serial; } public int getObject_state() { return this.object_state; } private void setObject_state(Map<String, Object> inUpdateMap, int object_state) { if (this.object_state != object_state) { this.object_state = object_state; inUpdateMap.put("object_state", object_state); } } public void setState(int object_state) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setObject_state(theUpdateMap, object_state); update(theUpdateMap); } public void overrideState(int inObject_state) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); this.object_state = inObject_state; theUpdateMap.put("object_state", inObject_state); update(theUpdateMap); } public void setModeAndState(int inMode, int inState) { final Map<String, Object> inUpdateMap = new HashMap<String, Object>(); setObject_mode(inUpdateMap, inMode); setObject_state(inUpdateMap, inState); update(inUpdateMap); } public int getObject_test() { return this.object_test; } private void setObject_test(Map<String, Object> inUpdateMap, int object_test) { if (this.object_test != object_test) { this.object_test = object_test; inUpdateMap.put("object_test", object_test); } } public void resetRebootState() { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setObject_test(theUpdateMap, 0); update(theUpdateMap); } public void setSleepTime(SleepTime inSleepTime) { setSleepTime(inSleepTime, true); } public void setSleepTime(SleepTime inSleepTime, boolean inUpdateState) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); Factories.OBJECT_SLEEP.setObjectSleepTime(this, inSleepTime); if (inUpdateState) { // calcul s'il est en veille ou pas final boolean isSleeping = ObjectSleep.ObjectSleepCommon.asleep(this); if (isXMPP()) { final List<String> resources = getResources(); // IQResourcesQuery.getClientResources(getXmppAddress()); if (isSleeping) { if (!resources.contains("asleep")) { sendXmppStatus(Message.MODE_VEILLE, JabberMessageFactory.IQ_STATUS_IDLE_MODE); } else { setObject_state(theUpdateMap, VObject.STATUS_VEILLE); } } else { if (resources.contains("asleep")) { sendXmppStatus(Message.MODE.ACTIF.getId(), JabberMessageFactory.IQ_STATUS_ASLEEP_MODE); } else { setObject_state(theUpdateMap, VObject.STATUS_ACTIF); } } } else { setObject_state(theUpdateMap, (isSleeping ? VObject.STATUS_VEILLE : VObject.STATUS_ACTIF)); } } update(theUpdateMap); } public Timezone getTimeZone() { return this.timeZone.get(this.time_zone); } private void setTimeZone(Map<String, Object> inUpdateMap, Timezone inValue) { if ((inValue != null) && !this.timeZone.equals(inValue)) { this.time_zone = inValue.getId(); inUpdateMap.put("time_zone", this.time_zone); this.timeZone.set(inValue); } } public void setTimeZone(Timezone inTimeZone) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setTimeZone(theUpdateMap, inTimeZone); update(theUpdateMap); } public long getObject_bc_version() { return this.object_bc_version; } public void setObject_bc_version(long inValue) { final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); setObject_bc_version(theUpdateMap, inValue); update(theUpdateMap); } private void setObject_bc_version(Map<String, Object> inUpdateMap, long inValue) { if (this.object_bc_version != inValue) { this.object_bc_version = (int) inValue; inUpdateMap.put("object_bc_version", inValue); } } // /* (non-Javadoc) // * @see net.violet.platform.datamodel.VObject#setVeilleObjetDeactivated() // */ public void setVeilleObjetDeactivated() { Factories.OBJECT_SLEEP.resetSleepTime(this); final Map<String, Object> theUpdateMap = new HashMap<String, Object>(); if (isXMPP()) { // TODO: changer la FSM pour spammer le lapin. sendXmppStatus(Message.MODE.ACTIF.getId(), JabberMessageFactory.ASLEEP_MODE); } setObject_state(theUpdateMap, VObject.STATUS_ACTIF); update(theUpdateMap); }