Permalink
Browse files

Code cleanup

  • Loading branch information...
mcicolella committed May 21, 2018
1 parent 73b3d2e commit be631f6045df67d89d6210b6a89e345983d83172
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2009-2016 Freedomotic team http://freedomotic.com
* Copyright (c) 2009-2018 Freedomotic team http://freedomotic.com
*
* This file is part of Freedomotic
*
@@ -119,13 +119,17 @@ public String getProperty(String key) {
}
}
/**
*
*
*/
private void init() {
eventName = this.getClass().getSimpleName();
isValid = true;
creation = System.currentTimeMillis();
}
private final void fillPayloadWithDefaults() {
private void fillPayloadWithDefaults() {
init();
try {
@@ -156,15 +160,19 @@ private final void fillPayloadWithDefaults() {
payload.addStatement("date",
datefmt.format(rightNow.getTime()));
//adding event.sender to event payload. So it can be used by trigger
payload.addStatement("sender",
getSender());
payload.addStatement("sender", getSender());
payload.addStatement("uuid", this.uuid);
payload.addStatement("type", this.type);
} catch (Exception e) {
LOG.error("Error while generating default data for event", e);
}
}
/**
*
*
* @return
*/
private String getSender() {
try {
if (sender != null) {
@@ -203,6 +211,7 @@ public String toString() {
}
/**
*
* @return the uuid
*/
public String getUuid() {
@@ -60,7 +60,7 @@ private ActiveMQConnectionFactory createFactory() {
+ "://"
+ config.getStringProperty("KEY_P2P_CLUSTER_NAME", Info.MESSAGING.BROKER_DEFAULT_CLUSTER_NAME)
+ "/" + Info.MESSAGING.BROKER_DEFAULT_UUID;
LOG.info("P2P Connection on " + KEY_P2P_BROKER_URL);
LOG.info("P2P Connection on {}", KEY_P2P_BROKER_URL);
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(KEY_P2P_BROKER_URL);
// tuned for performances
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2009-2016 Freedomotic team http://freedomotic.com
* Copyright (c) 2009-2018 Freedomotic team http://freedomotic.com
*
* This file is part of Freedomotic
*
@@ -96,6 +96,11 @@ public void onMessage(ObjectMessage message) {
}
/**
*
*
* @param event
*/
private void synchronizeLocalThing(ObjectHasChangedBehavior event) {
// Synchronize changed behaviors
EnvObjectLogic obj = thingsRepository.findOne(event.getProperty("object.uuid"));
@@ -105,7 +110,7 @@ private void synchronizeLocalThing(ObjectHasChangedBehavior event) {
Config conf = new Config();
conf.setProperty("value", value);
LOG.info("Synch thing \"{}\" behavior \"{}\" to \"{}\" notified by \"{}\"",
new Object[]{obj.getPojo().getName(), b.getName(), value});
new Object[]{obj.getPojo().getName(), b.getName(), value, event.getProperty("sender")});
obj.getBehavior(b.getName()).filterParams(conf, false);
}
}
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2009-2017 Freedomotic team http://freedomotic.com
* Copyright (c) 2009-2018 Freedomotic team http://freedomotic.com
*
* This file is part of Freedomotic
*
@@ -27,6 +27,9 @@
*
* @author Mauro Cicolella
*/
@SuppressWarnings("squid:S1948") //We are not planning to serialize UI components
public class MotionEvent
extends EventTemplate {
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2009-2016 Freedomotic team http://freedomotic.com
* Copyright (c) 2009-2018 Freedomotic team http://freedomotic.com
*
* This file is part of Freedomotic
*
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2009-2016 Freedomotic team http://freedomotic.com
* Copyright (c) 2009-2018 Freedomotic team http://freedomotic.com
*
* This file is part of Freedomotic
*
@@ -31,8 +31,9 @@
*
* @author Enrico Nicoletti
*/
public final class ProtocolRead
extends EventTemplate {
@SuppressWarnings("squid:S1948") //We are not planning to serialize UI components
public final class ProtocolRead extends EventTemplate {
private String protocol;
@Inject
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2009-2016 Freedomotic team http://freedomotic.com
* Copyright (c) 2009-2018 Freedomotic team http://freedomotic.com
*
* This file is part of Freedomotic
*
@@ -31,6 +31,9 @@
*
* @author Enrico Nicoletti
*/
@SuppressWarnings("squid:S1948") //We are not planning to serialize UI components
@XmlRootElement
public final class Reaction
implements Serializable {
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2009-2016 Freedomotic team http://freedomotic.com
* Copyright (c) 2009-2018 Freedomotic team http://freedomotic.com
*
* This file is part of Freedomotic
*
@@ -23,6 +23,7 @@
import com.freedomotic.core.SynchAction;
import com.freedomotic.environment.EnvironmentLogic;
import com.freedomotic.exceptions.DataUpgradeException;
import com.freedomotic.exceptions.FreedomoticRuntimeException;
import com.freedomotic.exceptions.RepositoryException;
import com.freedomotic.model.object.EnvObject;
import com.freedomotic.model.object.Representation;
@@ -144,15 +145,15 @@ private static void deleteObjectFiles(File folder) throws RepositoryException {
// This filter only returns object files
FileFilter objectFileFileter
= new FileFilter() {
@Override
public boolean accept(File file) {
if (file.isFile() && file.getName().endsWith(OBJECT_FILE_EXTENSION)) {
return true;
} else {
return false;
}
}
};
@Override
public boolean accept(File file) {
if (file.isFile() && file.getName().endsWith(OBJECT_FILE_EXTENSION)) {
return true;
} else {
return false;
}
}
};
files = folder.listFiles(objectFileFileter);
@@ -280,8 +281,8 @@ private static EnvObjectLogic getObjectByAddress(String protocol, String address
* @return
*/
@RequiresPermissions("objects:read")
private static ArrayList<EnvObjectLogic> getObjectByProtocol(String protocol) {
ArrayList<EnvObjectLogic> list = new ArrayList<>();
private static List<EnvObjectLogic> getObjectByProtocol(String protocol) {
List<EnvObjectLogic> list = new ArrayList<>();
for (Iterator<EnvObjectLogic> it = ThingRepositoryImpl.iterator(); it.hasNext();) {
EnvObjectLogic object = it.next();
if (object.getPojo().getProtocol().equalsIgnoreCase(protocol.trim()) // && auth.isPermitted("objects:read:" + object.getPojo().getUUID())
@@ -300,8 +301,8 @@ private static EnvObjectLogic getObjectByAddress(String protocol, String address
* @return
*/
@RequiresPermissions("objects:read")
private static ArrayList<EnvObjectLogic> getObjectByEnvironment(String uuid) {
ArrayList<EnvObjectLogic> list = new ArrayList<>();
private static List<EnvObjectLogic> getObjectByEnvironment(String uuid) {
List<EnvObjectLogic> list = new ArrayList<>();
for (Iterator<EnvObjectLogic> it = ThingRepositoryImpl.iterator(); it.hasNext();) {
EnvObjectLogic object = it.next();
if (object.getPojo().getEnvironmentID().equalsIgnoreCase(uuid) //&& auth.isPermitted("objects:read:" + object.getPojo().getUUID().substring(0, 7))
@@ -334,6 +335,11 @@ private static void remove(EnvObjectLogic input) {
input.destroy(); //free memory
}
/**
*
*
* @return
*/
private static List<String> getObjectsNames() {
List<String> list = new ArrayList<>();
for (EnvObjectLogic obj : objectList.values()) {
@@ -400,9 +406,8 @@ private EnvObjectLogic add(final EnvObjectLogic obj, final boolean MAKE_UNIQUE)
LOG.warn("Thing was created, but cannot set it as \"Changed\"", e);
}
} else {
throw new RuntimeException("Cannot add the same object more than one time");
throw new FreedomoticRuntimeException("Cannot add the same object more than one time");
}
return envObjectLogic;
}
@@ -496,7 +501,7 @@ public boolean delete(String uuid) {
eol.destroy();
return true;
} catch (Exception e) {
LOG.error("Cannot delete object" + uuid, e);
LOG.error("Cannot delete object \"{}\"", uuid, e);
return false;
}
}
@@ -599,17 +604,16 @@ public EnvObjectLogic load(File file) throws RepositoryException {
List<EnvObjectLogic> results = new ArrayList<>();
// This filter only returns object files
FileFilter objectFileFilter
= new FileFilter() {
@Override
public boolean accept(File file) {
if (file.isFile() && file.getName().endsWith(OBJECT_FILE_EXTENSION)) {
return true;
} else {
return false;
}
}
};
FileFilter objectFileFilter = new FileFilter() {
@Override
public boolean accept(File file) {
if (file.isFile() && file.getName().endsWith(OBJECT_FILE_EXTENSION)) {
return true;
} else {
return false;
}
}
};
File[] files = folder.listFiles(objectFileFilter);
@@ -33,6 +33,9 @@
*
* @author Enrico Nicoletti
*/
@SuppressWarnings("squid:S1948") //We are not planning to serialize UI components
public class ImageDrawer extends PlainDrawer {
private Protocol masterProtocol;
Oops, something went wrong.

0 comments on commit be631f6

Please sign in to comment.