Пример #1
0
    def process(self, _edObject=None):
        """
        Sends a store request and the screening object to the dbserver. Returns success or failure.
        
        Note that:
        * Any objects referred to by the object returned by self.getDataInput() will be stored. 
        * Primary key attributes should not be set.
        * If a foreign key attribute is not set, this method will attempt to find the foreign object among those 
        referred to by the self.getDataInput() object, and use the primary key attribute of this object when it 
        has been stored. If such an object is not found, the method fails.
        * The method will not attempt to store any more objects once an error is encountered
        """

        EDPluginExec.process(self)
        self.DEBUG("*** EDPluginISPyBv10.process")
        xsDataInputISPyB = self.getDataInput()
        self.m_xsDataResultISPyB = XSDataResultISPyB()

        xsDataISPyBScreening = xsDataInputISPyB.getScreening()
        if xsDataISPyBScreening == None:
            xsDataISPyBScreening = XSDataISPyBScreening()

        xsDataISPyBImage = xsDataInputISPyB.getImage()

        if xsDataISPyBScreening.getDataCollectionId() == None:
            if ((xsDataISPyBImage == None)
                    or (xsDataISPyBImage.getFileName() == None)
                    or (xsDataISPyBImage.getFileLocation() == None)):
                pyStrErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv10", "process", \
                                                                     "Neither a dataCollectionId nor a image filename + path are provided.")
                self.error(pyStrErrorMessage)
                self.addErrorMessage(pyStrErrorMessage)
                return

            strXML = EDUtilsXML.dnaMarshal(xsDataISPyBImage)

            # Send the XML to request the dataCollectionId from the dbserver:
            edStringResponse = self.httpPost(self.getDbserverHost(),
                                             self.getDbserverPort(),
                                             "/get_datacollectionid", strXML)

            if edStringResponse != None:
                # Handle response:
                self.DEBUG(edStringResponse)
                xsDatadbstatus = XSDatadbstatus.parseString(edStringResponse)
                pyStrCode = xsDatadbstatus.getCode()
                pyStrMessage = xsDatadbstatus.getMessage()
                self.DEBUG("dbserver returns code: " + pyStrCode)
                self.DEBUG("dbserver returns message: " + pyStrMessage)

                if (pyStrCode
                        == "error") or (xsDatadbstatus.getDataCollectionId()
                                        == -1):
                    if xsDatadbstatus.getDataCollectionId() == -1:
                        pyStrMessage = "An image corresponding to the given fileName and fileLocation was not found."
                    pyStrErrorMessage = EDMessage.ERROR_EXECUTION_03 % (
                        "EDPluginISPyBv10", "process", pyStrMessage)
                    self.error(pyStrErrorMessage)
                    self.addErrorMessage(pyStrErrorMessage)
                    return

                if xsDatadbstatus.getDataCollectionId() != -1:
                    xsDataISPyBScreening.setDataCollectionId(
                        XSDataInteger(xsDatadbstatus.getDataCollectionId()))
                    self.DEBUG("dataCollectionId is: " + str(
                        xsDataISPyBScreening.getDataCollectionId().getValue()))

        xsDataISPyBScreeningInput = xsDataInputISPyB.getScreeningInput()
        xsDataISPyBScreeningOutput = xsDataInputISPyB.getScreeningOutput()
        xsDataISPyBScreeningOutputLattice = xsDataInputISPyB.getScreeningOutputLattice(
        )
        xsDataISPyBScreeningRank = xsDataInputISPyB.getScreeningRank()
        xsDataISPyBScreeningRankSet = xsDataInputISPyB.getScreeningRankSet()
        xsDataISPyBScreeningStrategy = xsDataInputISPyB.getScreeningStrategy()

        for xsDataISPyBScreeningObject in [ xsDataISPyBScreening, xsDataISPyBScreeningRankSet, xsDataISPyBScreeningInput, xsDataISPyBScreeningOutput, \
                                      xsDataISPyBScreeningOutputLattice, xsDataISPyBScreeningRank, xsDataISPyBScreeningStrategy ]:

            if xsDataISPyBScreeningObject != None:

                # Set any missing foreign key attributes in xsDataScreeningObject:
                self.setForeignKeyAttributes(xsDataISPyBScreeningObject,
                                             self.m_xsDataResultISPyB)

                # Create DNA compatible XML from xsDataScreeningObject:
                strXML = EDUtilsXML.dnaMarshal(xsDataISPyBScreeningObject)

                # Send the XML to the dbserver:
                edStringResponse = self.httpPost(self.getDbserverHost(),
                                                 self.getDbserverPort(),
                                                 "/store_object_request",
                                                 strXML)

                if edStringResponse != None:
                    # Handle response:
                    self.DEBUG(edStringResponse)

                    xsDatadbstatus = XSDatadbstatus.parseString(
                        edStringResponse)

                    pyStrCode = xsDatadbstatus.getCode()
                    pyStrMessage = xsDatadbstatus.getMessage()
                    xsDataStrCode = XSDataString(pyStrCode)
                    xsDataStrMessage = XSDataString(pyStrMessage)
                    self.DEBUG("dbserver returns code: " + pyStrCode)
                    self.DEBUG("dbserver returns message: " + pyStrMessage)

                    xsDataResultStatusList = self.m_xsDataResultISPyB.getResultStatus(
                    )
                    xsDataResultStatus = XSDataResultStatus(
                        xsDataISPyBScreeningObject, xsDataStrCode,
                        xsDataStrMessage)
                    xsDataResultStatusList.append(xsDataResultStatus)

                    self.addToXSDataResultISPyB(self.m_xsDataResultISPyB,
                                                xsDatadbstatus)

                    if pyStrCode == "error":
                        pyStrErrorMessage = EDMessage.ERROR_EXECUTION_03 % (
                            "EDPluginISPyBv10", "process", pyStrMessage)
                        self.error(pyStrErrorMessage)
                        self.addErrorMessage(pyStrErrorMessage)
                        return
                else:
                    return
Пример #2
0
    def testSetDataModelInput(self):
        """
        A test for whether we can obtain the expected XML by setting a certain input for the plugin. 
        """
        edPluginISPyB = self.createPlugin()
        xsPluginItemISPyB = self.getPluginConfiguration(
            os.path.join(self.getPluginTestsDataHome(), "XSConfiguration.xml"))
        edPluginISPyB.setConfiguration(xsPluginItemISPyB)
        edPluginISPyB.configure()

        xsDataInputISPyB = XSDataInputISPyB()

        xsDataISPyBImage = XSDataISPyBImage()
        xsDataISPyBImage.setFileName(XSDataString("test.img"))
        xsDataISPyBImage.setFileLocation(XSDataString("/tmp"))

        xsDataISPyBScreening = XSDataISPyBScreening()
        #        xsDataISPyBScreening.setDataCollectionId( XSDataInteger ( 1 ) )
        xsDataISPyBScreening.setProgramVersion(XSDataString("EDNA Prototype"))

        xsDataISPyBScreeningInput = XSDataISPyBScreeningInput()
        xsDataISPyBScreeningInput.setBeamX(XSDataFloat(10.4))
        xsDataISPyBScreeningInput.setBeamY(XSDataFloat(2.31))
        xsDataISPyBScreeningInput.setRmsErrorLimits(XSDataFloat(0.8))
        xsDataISPyBScreeningInput.setMinimumFractionIndexed(XSDataFloat(0.4))
        xsDataISPyBScreeningInput.setMaximumFractionRejected(XSDataFloat(0.45))
        xsDataISPyBScreeningInput.setMinimumSignalToNoise(XSDataFloat(0.56))

        xsDataISPyBScreeningOutput = XSDataISPyBScreeningOutput()
        xsDataISPyBScreeningOutput.setStatusDescription(
            XSDataString("It's just fine."))
        xsDataISPyBScreeningOutput.setMosaicity(XSDataFloat(0.25))
        xsDataISPyBScreeningOutput.setBeamShiftX(XSDataFloat(0.141))
        xsDataISPyBScreeningOutput.setBeamShiftY(XSDataFloat(0.156))

        xsDataISPyBScreeningOutputLattice = XSDataISPyBScreeningOutputLattice()
        xsDataISPyBScreeningOutputLattice.setSpaceGroup(XSDataString("P222"))

        xsDataISPyBScreeningStrategy = XSDataISPyBScreeningStrategy()
        xsDataISPyBScreeningStrategy.setPhiStart(XSDataFloat(0))
        xsDataISPyBScreeningStrategy.setPhiEnd(XSDataFloat(20))
        xsDataISPyBScreeningStrategy.setRotation(XSDataFloat(1))
        xsDataISPyBScreeningStrategy.setProgram(XSDataString("EDNA"))
        xsDataISPyBScreeningStrategy.setAnomalous(XSDataBoolean(1))

        xsDataInputISPyB.setImage(xsDataISPyBImage)
        xsDataInputISPyB.setScreening(xsDataISPyBScreening)
        xsDataInputISPyB.setScreeningInput(xsDataISPyBScreeningInput)
        xsDataInputISPyB.setScreeningOutput(xsDataISPyBScreeningOutput)
        xsDataInputISPyB.setScreeningOutputLattice(
            xsDataISPyBScreeningOutputLattice)
        xsDataInputISPyB.setScreeningStrategy(xsDataISPyBScreeningStrategy)

        xsDataInputISPyB.outputFile(self.m_edObtainedInputFile)

        strExpectedInput = self.readAndParseFile(self.m_edReferenceInputFile)
        strObtainedInput = self.readAndParseFile(self.m_edObtainedInputFile)
        xsDataScreeningExpected = XSDataInputISPyB.parseString(
            strExpectedInput)
        xsDataScreeningObtained = XSDataInputISPyB.parseString(
            strObtainedInput)
        pyStrExpectedXML = xsDataScreeningExpected.marshal()
        pyStrObtainedXML = xsDataScreeningObtained.marshal()
        EDAssert.equal(pyStrExpectedXML, pyStrObtainedXML)

        self.cleanUp(edPluginISPyB)
    def process(self, _edObject=None):
        """
        Sends a store request and the screening object to the dbserver. Returns success or failure.
        
        Note that:
        * Any objects referred to by the object returned by self.getDataInput() will be stored. 
        * Primary key attributes should not be set.
        * If a foreign key attribute is not set, this method will attempt to find the foreign object among those 
        referred to by the self.getDataInput() object, and use the primary key attribute of this object when it 
        has been stored. If such an object is not found, the method fails.
        * The method will not attempt to store any more objects once an error is encountered
        """

        EDPluginExec.process(self)
        EDVerbose.DEBUG("*** EDPluginISPyBv10.process")
        xsDataInputISPyB = self.getDataInput()
        self.m_xsDataResultISPyB = XSDataResultISPyB()

        xsDataISPyBScreening = xsDataInputISPyB.getScreening()
        if xsDataISPyBScreening == None:
            xsDataISPyBScreening = XSDataISPyBScreening()

        xsDataISPyBImage = xsDataInputISPyB.getImage()

        if xsDataISPyBScreening.getDataCollectionId() == None:
            if ((xsDataISPyBImage == None) or (xsDataISPyBImage.getFileName() == None) or (xsDataISPyBImage.getFileLocation() == None)):
                pyStrErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv10", "process", \
                                                                     "Neither a dataCollectionId nor a image filename + path are provided.")
                EDVerbose.error(pyStrErrorMessage)
                self.addErrorMessage(pyStrErrorMessage)
                return

            strXML = EDUtilsXML.dnaMarshal(xsDataISPyBImage)

            # Send the XML to request the dataCollectionId from the dbserver:
            edStringResponse = self.httpPost(self.getDbserverHost(), self.getDbserverPort(), "/get_datacollectionid", strXML)

            if edStringResponse != None:
                # Handle response:
                EDVerbose.DEBUG(edStringResponse)
                xsDatadbstatus = XSDatadbstatus.parseString(edStringResponse)
                pyStrCode = xsDatadbstatus.getCode()
                pyStrMessage = xsDatadbstatus.getMessage()
                EDVerbose.DEBUG("dbserver returns code: " + pyStrCode)
                EDVerbose.DEBUG("dbserver returns message: " + pyStrMessage)

                if (pyStrCode == "error") or (xsDatadbstatus.getDataCollectionId() == -1):
                    if xsDatadbstatus.getDataCollectionId() == -1:
                        pyStrMessage = "An image corresponding to the given fileName and fileLocation was not found."
                    pyStrErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv10", "process", pyStrMessage)
                    EDVerbose.error(pyStrErrorMessage)
                    self.addErrorMessage(pyStrErrorMessage)
                    return

                if xsDatadbstatus.getDataCollectionId() != -1:
                    xsDataISPyBScreening.setDataCollectionId(XSDataInteger(xsDatadbstatus.getDataCollectionId()))
                    EDVerbose.DEBUG("dataCollectionId is: " + str(xsDataISPyBScreening.getDataCollectionId().getValue()))

        xsDataISPyBScreeningInput = xsDataInputISPyB.getScreeningInput()
        xsDataISPyBScreeningOutput = xsDataInputISPyB.getScreeningOutput()
        xsDataISPyBScreeningOutputLattice = xsDataInputISPyB.getScreeningOutputLattice()
        xsDataISPyBScreeningRank = xsDataInputISPyB.getScreeningRank()
        xsDataISPyBScreeningRankSet = xsDataInputISPyB.getScreeningRankSet()
        xsDataISPyBScreeningStrategy = xsDataInputISPyB.getScreeningStrategy()

        for xsDataISPyBScreeningObject in [ xsDataISPyBScreening, xsDataISPyBScreeningRankSet, xsDataISPyBScreeningInput, xsDataISPyBScreeningOutput, \
                                      xsDataISPyBScreeningOutputLattice, xsDataISPyBScreeningRank, xsDataISPyBScreeningStrategy ]:

            if xsDataISPyBScreeningObject != None:

                # Set any missing foreign key attributes in xsDataScreeningObject:
                self.setForeignKeyAttributes(xsDataISPyBScreeningObject, self.m_xsDataResultISPyB)

                # Create DNA compatible XML from xsDataScreeningObject:
                strXML = EDUtilsXML.dnaMarshal(xsDataISPyBScreeningObject)

                # Send the XML to the dbserver:
                edStringResponse = self.httpPost(self.getDbserverHost(), self.getDbserverPort(), "/store_object_request", strXML)

                if edStringResponse != None:
                    # Handle response:
                    EDVerbose.DEBUG(edStringResponse)

                    xsDatadbstatus = XSDatadbstatus.parseString(edStringResponse)

                    pyStrCode = xsDatadbstatus.getCode()
                    pyStrMessage = xsDatadbstatus.getMessage()
                    xsDataStrCode = XSDataString(pyStrCode)
                    xsDataStrMessage = XSDataString(pyStrMessage)
                    EDVerbose.DEBUG("dbserver returns code: " + pyStrCode)
                    EDVerbose.DEBUG("dbserver returns message: " + pyStrMessage)

                    xsDataResultStatusList = self.m_xsDataResultISPyB.getResultStatus()
                    xsDataResultStatus = XSDataResultStatus(xsDataISPyBScreeningObject, xsDataStrCode, xsDataStrMessage)
                    xsDataResultStatusList.append(xsDataResultStatus)

                    self.addToXSDataResultISPyB(self.m_xsDataResultISPyB, xsDatadbstatus)

                    if pyStrCode == "error":
                        pyStrErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv10", "process", pyStrMessage)
                        EDVerbose.error(pyStrErrorMessage)
                        self.addErrorMessage(pyStrErrorMessage)
                        return
                else:
                    return
    def testSetDataModelInput(self):
        """
        A test for whether we can obtain the expected XML by setting a certain input for the plugin. 
        """
        edPluginISPyB = self.createPlugin()
        xsPluginItemISPyB = self.getPluginConfiguration(os.path.join(self.getPluginTestsDataHome(), "XSConfiguration.xml"))
        edPluginISPyB.setConfiguration(xsPluginItemISPyB)
        edPluginISPyB.configure()

        xsDataInputISPyB = XSDataInputISPyB()

        xsDataISPyBImage = XSDataISPyBImage()
        xsDataISPyBImage.setFileName(XSDataString("test.img"))
        xsDataISPyBImage.setFileLocation(XSDataString("/tmp"))

        xsDataISPyBScreening = XSDataISPyBScreening()
#        xsDataISPyBScreening.setDataCollectionId( XSDataInteger ( 1 ) )
        xsDataISPyBScreening.setProgramVersion(XSDataString("EDNA Prototype"))

        xsDataISPyBScreeningInput = XSDataISPyBScreeningInput()
        xsDataISPyBScreeningInput.setBeamX(XSDataFloat(10.4))
        xsDataISPyBScreeningInput.setBeamY(XSDataFloat(2.31))
        xsDataISPyBScreeningInput.setRmsErrorLimits(XSDataFloat(0.8))
        xsDataISPyBScreeningInput.setMinimumFractionIndexed(XSDataFloat(0.4))
        xsDataISPyBScreeningInput.setMaximumFractionRejected(XSDataFloat(0.45))
        xsDataISPyBScreeningInput.setMinimumSignalToNoise(XSDataFloat(0.56))

        xsDataISPyBScreeningOutput = XSDataISPyBScreeningOutput()
        xsDataISPyBScreeningOutput.setStatusDescription(XSDataString("It's just fine."))
        xsDataISPyBScreeningOutput.setMosaicity(XSDataFloat(0.25))
        xsDataISPyBScreeningOutput.setBeamShiftX(XSDataFloat (0.141))
        xsDataISPyBScreeningOutput.setBeamShiftY(XSDataFloat (0.156))

        xsDataISPyBScreeningOutputLattice = XSDataISPyBScreeningOutputLattice()
        xsDataISPyBScreeningOutputLattice.setSpaceGroup(XSDataString("P222"))

        xsDataISPyBScreeningStrategy = XSDataISPyBScreeningStrategy()
        xsDataISPyBScreeningStrategy.setPhiStart(XSDataFloat(0))
        xsDataISPyBScreeningStrategy.setPhiEnd(XSDataFloat(20))
        xsDataISPyBScreeningStrategy.setRotation(XSDataFloat(1))
        xsDataISPyBScreeningStrategy.setProgram(XSDataString("EDNA"))
        xsDataISPyBScreeningStrategy.setAnomalous(XSDataBoolean(1))

        xsDataInputISPyB.setImage(xsDataISPyBImage)
        xsDataInputISPyB.setScreening(xsDataISPyBScreening)
        xsDataInputISPyB.setScreeningInput(xsDataISPyBScreeningInput)
        xsDataInputISPyB.setScreeningOutput(xsDataISPyBScreeningOutput)
        xsDataInputISPyB.setScreeningOutputLattice(xsDataISPyBScreeningOutputLattice)
        xsDataInputISPyB.setScreeningStrategy(xsDataISPyBScreeningStrategy)

        xsDataInputISPyB.outputFile(self.m_edObtainedInputFile)

        strExpectedInput = self.readAndParseFile (self.m_edReferenceInputFile)
        strObtainedInput = self.readAndParseFile (self.m_edObtainedInputFile)
        xsDataScreeningExpected = XSDataInputISPyB.parseString(strExpectedInput)
        xsDataScreeningObtained = XSDataInputISPyB.parseString(strObtainedInput)
        pyStrExpectedXML = xsDataScreeningExpected.marshal()
        pyStrObtainedXML = xsDataScreeningObtained.marshal()
        EDAssert.equal(pyStrExpectedXML, pyStrObtainedXML)

        self.cleanUp(edPluginISPyB)