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 681d15cff2ac46fdf94b8ef6b2d23823df2e7aa5..e17cd74905350fcff74dc46d358327328b131a15 100644 --- a/snapextractor/src/main/java/org/tango/server/snapextractor/SnapExtractor.java +++ b/snapextractor/src/main/java/org/tango/server/snapextractor/SnapExtractor.java @@ -94,6 +94,7 @@ import java.util.ResourceBundle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.tango.DeviceState; import org.tango.server.ServerManager; import org.tango.server.annotation.Attribute; @@ -126,6 +127,10 @@ import fr.soleil.archiving.snap.api.extractor.datasources.db.SnapReaderFactory; import fr.soleil.archiving.snap.api.extractor.naming.DynamicAttributeNamerFactory; import fr.soleil.archiving.snap.api.extractor.naming.IDynamicAttributeNamer; import fr.soleil.archiving.snap.api.manager.SnapManagerApi; +import fr.soleil.archiving.snap.api.model.Snapshot; +import fr.soleil.archiving.snap.api.persistence.SnapshotPersistenceManager; +import fr.soleil.archiving.snap.api.persistence.SnapshotPersistenceManagerFactory; +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; @@ -147,6 +152,10 @@ import fr.soleil.archiving.snap.api.tools.SnapshotingException; @Device public class SnapExtractor { + @Autowired + SnapshotDAO snapshotDao; + + private SnapshotPersistenceManager manager; private static final String _ERROR = "_ERROR"; @@ -162,6 +171,8 @@ public class SnapExtractor { @DeviceManagement private DeviceManager devManager; + + public void setDevManager(final DeviceManager devManager) { this.devManager = devManager; } @@ -228,6 +239,13 @@ public class SnapExtractor { this.isRac = isRac; } + @DeviceProperty(name = "beansFileName", description = "", defaultValue = "") + private String beansFileName = ""; + + public void setBeansFileName(String beansFileName) { + this.beansFileName = beansFileName; + } + private ISnapReader snapReader; /** @@ -297,6 +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); } catch (final SnapshotingException e) { logger.error("Failed to initialize device", e); throw e.toTangoException(); @@ -406,6 +427,31 @@ 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 "GetSnapValue" on device. Loads a snapshot of given ID: * if the snapshot exists, find if the attribute exists for this snapshot if @@ -649,13 +695,6 @@ public class SnapExtractor { } else if (writable == AttrWriteType._READ_WRITE) { dynMngt.addAttribute(new SnapDynamicAttribute(writeName, writeDbData)); } -// devManager.startPolling(readName, 0); - // add data to polling buffer -// final int dataLength = dbData.getDataAsTimedAttrData().length; -// for (int i = 0; i < dataLength; i++) { -// devManager.triggerPolling(readName); -// devManager.triggerPolling(writeName); -// } } @Command(name = "GetAttributeListForContext", inTypeDesc = "Context ID", outTypeDesc = "The list of attributes contained in the given context")