diff --git a/pom.xml b/pom.xml index 6217bbc08c5a79feb0b71931e6cfbbe3b1f6cfb0..3c346a2012e1daf7a7d9bf5c4a8472f2855dc083 100644 --- a/pom.xml +++ b/pom.xml @@ -1,59 +1,58 @@ <?xml version="1.0" encoding="UTF-8"?> -<project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>fr.soleil.maven.parent</groupId> - <artifactId>java-updated-versions</artifactId> - <version>0-SNAPSHOT</version> - </parent> + <parent> + <groupId>fr.soleil.maven.parent</groupId> + <artifactId>java-updated-versions</artifactId> + <version>0-SNAPSHOT</version> + </parent> - <groupId>fr.soleil.deviceservers</groupId> - <artifactId>snaparchivingservers</artifactId> - <version>1.7.15</version> - <packaging>pom</packaging> - <name>snapArchivingServers</name> - <developers> - <developer> - <id>abeille</id> - <name>Gwenaelle Abeille</name> - <email>gwenaelle.abeille@synchrotron-soleil.fr</email> - <organization>Synchrotron Soleil</organization> - <organizationUrl>http://www.synchrotron-soleil.fr</organizationUrl> - <roles> - <role>Java Developer</role> - </roles> - <timezone>1</timezone> - </developer> - <developer> - <id>girardot</id> - <name>Raphaël GIRARDOT</name> - <email>raphael.girardot@synchrotron-soleil.fr</email> - <organization>Synchrotron Soleil</organization> - <organizationUrl>http://www.synchrotron-soleil.fr</organizationUrl> - <roles> - <role>Java Developer</role> - </roles> - <timezone>1</timezone> - </developer> - </developers> + <groupId>fr.soleil.deviceservers</groupId> + <artifactId>snaparchivingservers</artifactId> + <version>1.7.15</version> + <packaging>pom</packaging> + <name>snapArchivingServers</name> + <developers> + <developer> + <id>abeille</id> + <name>Gwenaelle Abeille</name> + <email>gwenaelle.abeille@synchrotron-soleil.fr</email> + <organization>Synchrotron Soleil</organization> + <organizationUrl>http://www.synchrotron-soleil.fr</organizationUrl> + <roles> + <role>Java Developer</role> + </roles> + <timezone>1</timezone> + </developer> + <developer> + <id>girardot</id> + <name>Raphaël GIRARDOT</name> + <email>raphael.girardot@synchrotron-soleil.fr</email> + <organization>Synchrotron Soleil</organization> + <organizationUrl>http://www.synchrotron-soleil.fr</organizationUrl> + <roles> + <role>Java Developer</role> + </roles> + <timezone>1</timezone> + </developer> + </developers> - <scm> - <connection>${scm.connection.svn.tango-cs}:archiving/server/snapArchivingServers/trunk</connection> - <developerConnection>${scm.developerConnection.svn.tango-cs}:archiving/server/snapArchivingServers/trunk</developerConnection> - <url>${scm.url.svn.tango-cs}/archiving/server/snapArchivingServers/trunk</url> - </scm> + <scm> + <connection>${scm.connection.svn.tango-cs}:archiving/server/snapArchivingServers/trunk</connection> + <developerConnection>${scm.developerConnection.svn.tango-cs}:archiving/server/snapArchivingServers/trunk</developerConnection> + <url>${scm.url.svn.tango-cs}/archiving/server/snapArchivingServers/trunk</url> + </scm> - <modules> - <module>snaparchiver</module> - <module>snapmanager</module> - <module>snapextractor</module> - </modules> + <modules> + <module>snaparchiver</module> + <module>snapmanager</module> + <module>snapextractor</module> + </modules> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> </project> diff --git a/snapextractor/src/main/java/org/tango/server/snapextractor/SnapExtractor.java b/snapextractor/src/main/java/org/tango/server/snapextractor/SnapExtractor.java index e17cd74905350fcff74dc46d358327328b131a15..dd56eb6b1228096292c1d71a2f70eb8d35f7a546 100644 --- a/snapextractor/src/main/java/org/tango/server/snapextractor/SnapExtractor.java +++ b/snapextractor/src/main/java/org/tango/server/snapextractor/SnapExtractor.java @@ -133,6 +133,8 @@ import fr.soleil.archiving.snap.api.persistence.SnapshotPersistenceManagerFactor import fr.soleil.archiving.snap.api.persistence.spring.dao.SnapshotDAO; import fr.soleil.archiving.snap.api.tools.SnapAttributeExtract; import fr.soleil.archiving.snap.api.tools.SnapshotingException; +import fr.soleil.database.DBExtractionConst; +import fr.soleil.lib.project.ObjectUtils; /** * Class Description: This device is in charge of extracting snapshots from the @@ -151,11 +153,11 @@ import fr.soleil.archiving.snap.api.tools.SnapshotingException; // --------- End of States Description ---------- @Device -public class SnapExtractor { - @Autowired - SnapshotDAO snapshotDao; +public class SnapExtractor implements DBExtractionConst { + @Autowired + SnapshotDAO snapshotDao; - private SnapshotPersistenceManager manager; + private SnapshotPersistenceManager manager; private static final String _ERROR = "_ERROR"; @@ -171,14 +173,12 @@ public class SnapExtractor { @DeviceManagement private DeviceManager devManager; - - public void setDevManager(final DeviceManager devManager) { this.devManager = devManager; } @Attribute(name = "version", displayLevel = DispLevel._EXPERT) - @AttributeProperties(description = "The version of the device", label = "version", unit = "") + @AttributeProperties(description = "The version of the device", label = "version", unit = ObjectUtils.EMPTY_STRING) private final String version = ResourceBundle.getBundle("application").getString("project.version"); public String getVersion() { @@ -191,7 +191,7 @@ public class SnapExtractor { * User identifier (name) used to connect the database SNAP. <br> * <b>Default value : </b> snap */ - @DeviceProperty(name = "dbUser", description = "", defaultValue = "") + @DeviceProperty(name = "dbUser", description = ObjectUtils.EMPTY_STRING, defaultValue = ObjectUtils.EMPTY_STRING) private String dbUser; public void setDbUser(final String dbUser) { @@ -202,7 +202,7 @@ public class SnapExtractor { * Password used to connect the database SNAP. <br> * <b>Default value : </b> snap */ - @DeviceProperty(name = "dbPassword", description = "", defaultValue = "") + @DeviceProperty(name = "dbPassword", description = ObjectUtils.EMPTY_STRING, defaultValue = ObjectUtils.EMPTY_STRING) private String dbPassword; public void setDbPassword(final String dbPassword) { @@ -211,40 +211,40 @@ public class SnapExtractor { protected int formerState = DevState._UNKNOWN; - @DeviceProperty(name = "dbHost", description = "", defaultValue = "") + @DeviceProperty(name = "dbHost", description = ObjectUtils.EMPTY_STRING, defaultValue = ObjectUtils.EMPTY_STRING) private String dbHost; public void setDbHost(final String dbHost) { this.dbHost = dbHost; } - @DeviceProperty(name = "dbName", description = "", defaultValue = "") + @DeviceProperty(name = "dbName", description = ObjectUtils.EMPTY_STRING, defaultValue = ObjectUtils.EMPTY_STRING) private String dbName; public void setDbName(final String dbName) { this.dbName = dbName; } - @DeviceProperty(name = "dbSchema", description = "", defaultValue = "") + @DeviceProperty(name = "dbSchema", description = ObjectUtils.EMPTY_STRING, defaultValue = ObjectUtils.EMPTY_STRING) private String dbSchema; public void setDbSchema(final String dbSchema) { this.dbSchema = dbSchema; } - @DeviceProperty(name = "isRac", description = "", defaultValue = "") + @DeviceProperty(name = "isRac", description = ObjectUtils.EMPTY_STRING, defaultValue = ObjectUtils.EMPTY_STRING) private String isRac; public void setIsRac(final String isRac) { this.isRac = isRac; } - @DeviceProperty(name = "beansFileName", description = "", defaultValue = "") - private String beansFileName = ""; + @DeviceProperty(name = "beansFileName", description = ObjectUtils.EMPTY_STRING, defaultValue = ObjectUtils.EMPTY_STRING) + private String beansFileName = ObjectUtils.EMPTY_STRING; - public void setBeansFileName(String beansFileName) { - this.beansFileName = beansFileName; - } + public void setBeansFileName(String beansFileName) { + this.beansFileName = beansFileName; + } private ISnapReader snapReader; @@ -315,9 +315,9 @@ public class SnapExtractor { SnapManagerApi.initSnapConnection(dbHost, dbName, dbSchema, dbUser, dbPassword, isRac); snapReader = SnapReaderFactory.getImpl(SnapReaderFactory.REAL); snapReader.openConnection(); - SnapshotPersistenceManagerFactory factory = SnapshotPersistenceManagerFactory.getInstance(); - manager = factory.getManager(beansFileName, dbUser, dbPassword); - manager.autowired(this); + SnapshotPersistenceManagerFactory factory = SnapshotPersistenceManagerFactory.getInstance(); + manager = factory.getManager(beansFileName, dbUser, dbPassword); + manager.autowired(this); } catch (final SnapshotingException e) { logger.error("Failed to initialize device", e); throw e.toTangoException(); @@ -427,30 +427,30 @@ public class SnapExtractor { return addAttributes(sae); } - /** - * Execute command "GetSnap" on device. Loads a snapshot of given ID: if the - * snapshot exists, creates for each one of the snapshot's attributes a dynamic - * attribute for its read part, and, if the attribute isn't read-only, for its - * write part. Returns a table containing, as many times as there are attributes - * for the specified snapshot: - * <UL> - * <LI>the attribute complete name - * <LI>the name of the dynamic attribute containing the attribute's read value - * (if it has one, otherwise blank) - * <LI>the name of the dynamic attribute containing the attribute's write value - * (if it has one, otherwise blank) - * </UL> - * - * @param argin the snapshot's ID - * @return A table containing [attrRealName, dynAttrNameR,dynAttrNameW]*n - * @throws DevFailed - */ - @Command(name = "GetSnapTime", inTypeDesc = "snapID", outTypeDesc = "[attrRealName, dynAttrNameW,dynAttrNameR]*n") - public String getSnapTime(final int argin) throws DevFailed { - logger.info("get snap time with id {}", argin); - Snapshot snap = snapshotDao.findOne(argin); - return "Date snapshot : " + snap.getTime(); - } + /** + * Execute command "GetSnap" on device. Loads a snapshot of given ID: if the + * snapshot exists, creates for each one of the snapshot's attributes a dynamic + * attribute for its read part, and, if the attribute isn't read-only, for its + * write part. Returns a table containing, as many times as there are attributes + * for the specified snapshot: + * <UL> + * <LI>the attribute complete name + * <LI>the name of the dynamic attribute containing the attribute's read value + * (if it has one, otherwise blank) + * <LI>the name of the dynamic attribute containing the attribute's write value + * (if it has one, otherwise blank) + * </UL> + * + * @param argin the snapshot's ID + * @return A table containing [attrRealName, dynAttrNameR,dynAttrNameW]*n + * @throws DevFailed + */ + @Command(name = "GetSnapTime", inTypeDesc = "snapID", outTypeDesc = "[attrRealName, dynAttrNameW,dynAttrNameR]*n") + public String getSnapTime(final int argin) throws DevFailed { + logger.info("get snap time with id {}", argin); + Snapshot snap = snapshotDao.findOne(argin); + return "Date snapshot : " + snap.getTime(); + } /** * Execute command "GetSnapValue" on device. Loads a snapshot of given ID: @@ -622,7 +622,7 @@ public class SnapExtractor { final IConverter converter = ConverterFactory.getImpl(ConverterFactory.DEFAULT); // try to extract all values try { - final DbData dbData = converter.convert(currentExtract); + final DbData[] dbData = converter.convert(currentExtract); if (dbData == null) { logger.error( "Null DbData for attribute {} (if the attribute is R/W or is a spectrum, at least one of its value's component is null)", @@ -633,8 +633,7 @@ public class SnapExtractor { this.createDynamicAttribute(dbData, names); } } catch (final DevFailed e) { - logger.error("", e); - logger.error(DevFailedUtils.toString(e)); + logger.error(DevFailedUtils.toString(e), e); names = getErrorNames(currentExtract); } } @@ -663,7 +662,7 @@ public class SnapExtractor { final boolean firstIsRead = currentExtract.getWritable() != AttrWriteType._WRITE; final String randomName1 = dynamicAttributeNamer.getName(currentExtract, id, firstIsRead); - String randomName2 = ""; + String randomName2 = ObjectUtils.EMPTY_STRING; if (hasBothReadAndWriteValues) { randomName2 = dynamicAttributeNamer.getName(currentExtract, id, !firstIsRead); } @@ -674,18 +673,20 @@ public class SnapExtractor { return names; } - private void createDynamicAttribute(final DbData dbData, final String[] names) throws DevFailed { + private void createDynamicAttribute(final DbData[] dbDatas, final String[] names) throws DevFailed { final String readName = names[0]; final String writeName = names[1]; - if (dbData.getDataType() == TangoConst.Tango_DEV_STATE) { - dbData.setDataType(TangoConst.Tango_DEV_LONG); + int writable = -1; + for (DbData dbData : dbDatas) { + if ((dbData != null) && (dbData.getDataType() == TangoConst.Tango_DEV_STATE)) { + dbData.setDataType(TangoConst.Tango_DEV_LONG); + writable = dbData.getWritable(); + } } - final DbData[] dbDatas = dbData.splitDbData(); - final DbData readDbData = dbDatas[0]; - final DbData writeDbData = dbDatas[1]; + final DbData readDbData = dbDatas[READ_INDEX]; + final DbData writeDbData = dbDatas[WRITE_INDEX]; logger.debug("read part = {}, write part = {}", readDbData, writeDbData); // Create the attributes - final int writable = dbData.getWritable(); if (writable == AttrWriteType._READ || writable == AttrWriteType._READ_WRITE) { logger.debug("create attribute {}", readName); dynMngt.addAttribute(new SnapDynamicAttribute(readName, readDbData));