Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • DM/dm-docs
  • hammonds/dm-docs
  • hparraga/dm-docs
3 results
Show changes
Showing
with 778 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<div class="actionButton">
<p:commandButton id="userExperimentRoleAddButton"
action="#{userInfoController.prepareAddUserExperimentRole(userInfoObject)}"
oncomplete="PF('userExperimentRoleAddDialogWidget').show()"
rendered="#{loginController.admin}"
value="Add" alt="Add user experiment role." icon="ui-icon-plus">
<p:tooltip for="userExperimentRoleAddButton" value="Add user experiment role."/>
</p:commandButton>
</div>
<ui:include src="userExperimentRoleAddDialog.xhtml"/>
<ui:param name="breadcrumb" value="#{userInfoController.currentViewId}"/>
<ui:param name="breadcrumbObjectId" value="#{userInfoObject.id}"/>
<p:dataTable id="userExperimentRoleListDataTable"
var="userExperimentRoleObject"
value="#{userInfoObject.userExperimentRoleList}"
paginator="true"
paginatorAlwaysVisible="false"
rows="#{userInfoController.displayNumberOfItemsPerPage}"
widgetVar="userExperimentRoleListWidget"
emptyMessage="No experiments found.">
<p:column sortBy="#{userExperimentRoleObject.experiment.name}" headerText="Experiment Name"
filterBy="#{userExperimentRoleObject.experiment.name}" filterMatchMode="contains" >
<h:outputLink value="../experiment/view.xhtml?id=#{userExperimentRoleObject.experiment.id}&amp;breadcrumb=#{breadcrumb}&amp;breadcrumbObjectId=#{breadcrumbObjectId}"
title="Experiment: #{userExperimentRoleObject.experiment.name}">
<h:outputText value="#{userExperimentRoleObject.experiment.name}"/>
</h:outputLink>
</p:column>
<p:column sortBy="#{userExperimentRoleObject.experiment.experimentType.name}" headerText="Experiment Type"
filterBy="#{userExperimentRoleObject.experiment.experimentType.name}" filterMatchMode="contains" >
<h:outputText value="#{userExperimentRoleObject.experiment.experimentType.name}"/>
</p:column>
<p:column sortBy="#{userExperimentRoleObject.experiment.experimentStation.name}" headerText="Experiment Station"
filterBy="#{userExperimentRoleObject.experiment.experimentStation.name}" filterMatchMode="contains" >
<h:outputText value="#{userExperimentRoleObject.experiment.experimentStation.name}"/>
</p:column>
<p:column sortBy="#{userExperimentRoleObject.experimentRoleType.name}" headerText="Role"
filterBy="#{userExperimentRoleObject.experimentRoleType.name}" filterMatchMode="contains" >
<h:outputText value="#{userExperimentRoleObject.experimentRoleType.name}"/>
</p:column>
<p:column headerText="Actions" >
<div class="actionLink">
<p:commandLink action="#{userInfoController.deleteUserExperimentRole(userExperimentRoleObject)}"
styleClass="ui-icon ui-icon-trash" title="Delete"
update="userExperimentRoleListDataTable"
rendered="#{loginController.admin}"
immediate="true"/>
</div>
</p:column>
</p:dataTable>
</ui:composition>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:param name="userInfoObject" value="#{userInfoController.selected}"/>
<p:panelGrid columns="2" styleClass="createEntityDetails">
<h:outputLabel for="badge" value="Badge" styleClass="entityDataEmphasizedLabel"/>
<h:inputText id="badge" value="#{userInfoObject.badge}" title="Badge" styleClass="entityDataEmphasizedInputText"/>
<h:outputLabel for="username" value="Username" styleClass="entityDataEmphasizedLabel"/>
<h:inputText id="username" value="#{userInfoObject.username}" title="Username" styleClass="entityDataEmphasizedInputText"/>
<h:outputLabel for="lastName" value="Last Name" styleClass="entityDataLabel"/>
<h:inputText id="lastName" value="#{userInfoObject.lastName}" title="Last Name" styleClass="entityDataInputText"/>
<h:outputLabel for="firstName" value="First Name" styleClass="entityDataLabel"/>
<h:inputText id="firstName" value="#{userInfoObject.firstName}" title="First Name" styleClass="entityDataInputText"/>
<h:outputLabel for="middleName" value="Middle Name" styleClass="entityDataLabel"/>
<h:inputText id="middleName" value="#{userInfoObject.middleName}" title="Middle Name" styleClass="entityDataInputText"/>
<h:outputLabel for="email" value="Email" styleClass="entityDataLabel"/>
<h:inputText id="email" value="#{userInfoObject.email}" title="Email" styleClass="entityDataInputText"/>
<h:outputLabel for="password" value="Password" styleClass="entityDataLabel"/>
<p:password id="password" value="#{userInfoController.passwordEntry}" title="Password" feedback="true" styleClass="entityDataInputText"/>
<h:outputLabel for="globusUsername" value="Globus Username" styleClass="entityDataEmphasizedLabel"/>
<h:inputText id="globusUsername" value="#{userInfoObject.globusUsername}" title="Globus Username" styleClass="entityDataEmphasizedInputText"/>
<h:outputLabel for="description" value="Description" styleClass="entityDataLabel"/>
<h:inputText id="description" value="#{userInfoObject.description}" title="Description" styleClass="entityDataInputText"/>
</p:panelGrid>
</ui:composition>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<p:confirmDialog id="userInfoDestroyDialog" message="Delete user #{userInfoController.getCurrentEntityInstanceName()}?"
header="Delete User" severity="alert" widgetVar="userInfoDestroyDialogWidget"
styleClass="dialog">
<p:commandButton value="Yes" oncomplete="userInfoDestroyDialogWidget.hide()" action="#{userInfoController.destroy()}"/>
<p:commandButton value="No" onclick="PF('userInfoDestroyDialogWidget').hide()" type="button" />
</p:confirmDialog>
</ui:composition>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:param name="userInfoObject" value="#{userInfoController.selected}"/>
<ui:param name="isFieldWriteable" value="#{loginController.loggedIn}"/>
<p:panelGrid columns="2" styleClass="editEntityDetails">
<h:outputLabel for="badge" value="Badge" styleClass="entityDataEmphasizedLabel"/>
<h:outputText id="badge" value="#{userInfoObject.badge}" title="Badge" styleClass="entityDataEmphasizedText"/>
<h:outputLabel for="username" value="Username" styleClass="entityDataEmphasizedLabel"/>
<h:inputText id="username" value="#{userInfoObject.username}" rendered="#{isFieldWriteable}" title="Username" styleClass="entityDataEmphasizedInputText"/>
<h:outputText id="usernameOutput" value="#{userInfoObject.username}" rendered="#{!isFieldWriteable}" title="Username" styleClass="entityDataEmphasizedText"/>
<h:outputLabel for="lastName" value="Last Name" styleClass="entityDataLabel"/>
<h:inputText id="lastName" value="#{userInfoObject.lastName}" rendered="#{isFieldWriteable}" title="Last Name" styleClass="entityDataInputText"/>
<h:outputText id="lastNameOutput" value="#{userInfoObject.lastName}" rendered="#{!isFieldWriteable}" title="Last Name" styleClass="entityDataText"/>
<h:outputLabel for="firstName" value="First Name" styleClass="entityDataLabel"/>
<h:inputText id="firstName" value="#{userInfoObject.firstName}" rendered="#{isFieldWriteable}" title="First Name" styleClass="entityDataInputText"/>
<h:outputText id="firstNameOutput" value="#{userInfoObject.firstName}" rendered="#{!isFieldWriteable}" title="First Name" styleClass="entityDataText"/>
<h:outputLabel for="middleName" value="Middle Name" styleClass="entityDataLabel"/>
<h:inputText id="middleName" value="#{userInfoObject.middleName}" title="Middle Name" rendered="#{isFieldWriteable}" styleClass="entityDataInputText"/>
<h:outputText id="middleNameOutput" value="#{userInfoObject.middleName}" title="Middle Name" rendered="#{!isFieldWriteable}" styleClass="entityDataText"/>
<h:outputLabel for="email" value="Email" styleClass="entityDataLabel"/>
<h:inputText id="email" value="#{userInfoObject.email}" title="Email" styleClass="entityDataInputText"/>
<h:outputLabel for="password" value="Password" styleClass="entityDataLabel" rendered="#{userInfoObject.isLocalUser()}"/>
<p:password id="password" rendered="#{userInfoObject.isLocalUser()}" value="#{userInfoController.passwordEntry}" title="Password" feedback="true" styleClass="entityDataInputText"/>
<h:outputLabel for="globusUsername" value="Globus Username" styleClass="entityDataLabel"/>
<h:inputText id="globusUsername" value="#{userInfoObject.globusUsername}" title="Globus Username" styleClass="entityDataInputText"/>
<h:outputLabel for="description" value="Description" styleClass="entityDataLabel"/>
<h:inputText id="description" value="#{userInfoObject.description}" title="Description" styleClass="entityDataInputText"/>
</p:panelGrid>
</ui:composition>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<p:dataTable id="userInfoListDataTable"
var="userInfoObject"
value="#{userInfoController.listDataModel}"
filteredValue="#{userInfoController.filteredObjectList}"
paginator="true"
paginatorAlwaysVisible="false"
rows="#{userInfoController.displayNumberOfItemsPerPage}"
widgetVar="userInfoListWidget"
emptyMessage="No users found.">
<p:ajax event="filter" listener="#{userInfoController.onFilterChange}"/>
<p:column sortBy="#{userInfoObject.id}" headerText="Id" >
<h:outputText value="#{userInfoObject.id}"/>
</p:column>
<p:column sortBy="#{userInfoObject.badge}" headerText="ANL Badge"
filterBy="#{userInfoObject.badge}" filterMatchMode="contains"
filterValue="#{userInfoController.filterByBadge}" >
<h:outputText value="#{userInfoObject.badge}"/>
</p:column>
<p:column sortBy="#{userInfoObject.username}" headerText="Username"
filterBy="#{userInfoObject.username}" filterMatchMode="contains"
filterValue="#{userInfoController.filterByUsername}" >
<h:outputText value="#{userInfoObject.username}"/>
</p:column>
<p:column sortBy="#{userInfoObject.lastName}" headerText="Last Name"
filterBy="#{userInfoObject.lastName}" filterMatchMode="contains"
filterValue="#{userInfoController.filterByLastName}" >
<h:outputText value="#{userInfoObject.lastName}"/>
</p:column>
<p:column sortBy="#{userInfoObject.firstName}" headerText="First, Middle Name"
filterBy="#{userInfoObject.firstName}" filterMatchMode="contains"
filterValue="#{userInfoController.filterByFirstName}" >
<h:outputText value="#{userInfoObject.firstName} #{userInfoObject.middleName}"/>
</p:column>
<p:column sortBy="#{userInfoObject.email}" headerText="Email"
filterBy="#{userInfoObject.email}" filterMatchMode="contains"
filterValue="#{userInfoController.filterByEmail}" >
<h:outputText value="#{userInfoObject.email}"/>
</p:column>
<p:column sortBy="#{userInfoObject.globusUsername}" headerText="Globus Username"
filterBy="#{userInfoObject.globusUsername}" filterMatchMode="contains"
filterValue="#{userInfoController.filterByGlobusUsername}" >
<h:outputText value="#{userInfoObject.globusUsername}"/>
</p:column>
<p:column sortBy="#{userInfoObject.description}" headerText="Description"
filterBy="#{userInfoObject.description}" filterMatchMode="contains"
filterValue="#{userInfoController.filterByDescription}" >
<h:outputText value="#{userInfoObject.description}"/>
</p:column>
<p:column headerText="Actions" >
<div class="actionLink">
<p:commandLink action="#{userInfoController.prepareView(userInfoObject)}" styleClass="ui-icon ui-icon-info" title="View">
<f:setPropertyActionListener value="#{userInfoObject}" target="#{userInfoController.current}"/>
</p:commandLink>
<p:commandLink action="#{userInfoController.prepareEdit(userInfoObject)}" rendered="#{loginController.admin}" styleClass="ui-icon ui-icon-pencil" title="Edit"/>
<p:commandLink oncomplete="PF('userInfoDestroyDialogWidget').show()" rendered="#{loginController.admin}" styleClass="ui-icon ui-icon-trash" title="Delete" update="@form">
<f:setPropertyActionListener value="#{userInfoObject}" target="#{userInfoController.current}"/>
</p:commandLink>
</div>
</p:column>
</p:dataTable>
</ui:composition>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:param name="userInfoObject" value="#{userInfoController.selected}"/>
<p:panelGrid columns="2" styleClass="viewEntityDetails">
<h:outputLabel for="badge" value="Badge" styleClass="entityDataEmphasizedLabel"/>
<h:outputText id="badge" value="#{userInfoObject.badge}" title="Badge" styleClass="entityDataEmphasizedText"/>
<h:outputLabel for="username" value="Username" styleClass="entityDataEmphasizedLabel"/>
<h:outputText id="username" value="#{userInfoObject.username}" title="Username" styleClass="entityDataEmphasizedText"/>
<h:outputLabel for="lastName" value="Last Name" styleClass="entityDataLabel"/>
<h:outputText id="lastName" value="#{userInfoObject.lastName}" title="Last Name" styleClass="entityDataText"/>
<h:outputLabel for="firstName" value="First Name" styleClass="entityDataLabel"/>
<h:outputText id="firstName" value="#{userInfoObject.firstName}" title="First Name" styleClass="entityDataText"/>
<h:outputLabel for="middleName" value="Middle Name" styleClass="entityDataLabel"/>
<h:outputText id="middleName" value="#{userInfoObject.middleName}" title="Middle Name" styleClass="entityDataText"/>
<h:outputLabel for="email" value="Email" styleClass="entityDataLabel"/>
<h:outputText id="email" value="#{userInfoObject.email}" title="Email" styleClass="entityDataText"/>
<h:outputLabel for="globusUsername" value="Globus Username" styleClass="entityDataLabel"/>
<h:outputText id="globusUsername" value="#{userInfoObject.globusUsername}" title="Globus Username" styleClass="entityDataText"/>
<h:outputLabel for="description" value="Description" styleClass="entityDataLabel"/>
<h:outputText id="description" value="#{userInfoObject.description}" title="Description" styleClass="entityDataText"/>
</p:panelGrid>
</ui:composition>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<f:metadata>
<f:event type="preRenderComponent" listener="#{userInfoController.processViewRequestParams}"/>
</f:metadata>
<title>User View</title>
<ui:composition template="../../templates/dmViewTemplate.xhtml">
<ui:define name="middleCenter">
<h:form id="viewUserInfoForm" rendered="#{userInfoController.entitySelected}">
<div class="pageTitle">
<h1>User #{userInfoController.current.username}</h1>
</div>
<ui:param name="entityController" value="#{userInfoController}"/>
<ui:param name="userInfoObject" value="#{userInfoController.current}"/>
<p:accordionPanel multiple="true" activeIndex="0,1" >
<p:tab title="User Data">
<div class="middleCenterLeftContent">
<ui:include src="private/userInfoViewPanelGrid.xhtml"/>
<p/>
<div class="actionButton">
<p:commandButton action="#{userInfoController.prepareEdit(userInfoObject)}" rendered="#{loginController.admin}" value="Edit" alt="Edit" icon="ui-icon-pencil"/>
<p:commandButton onclick="PF('userInfoDestroyDialogWidget').show();" rendered="#{loginController.admin}" value="Delete" alt="Delete" icon="ui-icon-trash">
<f:setPropertyActionListener value="#{userInfoObject}" target="#{userInfoController.current}"/>
</p:commandButton>
<p:commandButton action="#{userInfoController.followBreadcrumbOrPrepareList()}" value="Return" alt="Return" icon="ui-icon-arrowreturnthick-1-w"/>
</div>
</div>
</p:tab>
<p:tab title="User Experiment Roles">
<div class="middleCenterLeftContent">
<ui:include src="private/userExperimentRoleListDataTable.xhtml"/>
</div>
</p:tab>
</p:accordionPanel>
<p/>
<div class="actionButton">
<p:commandButton action="#{userInfoController.followBreadcrumbOrPrepareList()}" value="Return" alt="Return" icon="ui-icon-arrowreturnthick-1-w"/>
</div>
<ui:include src="private/userInfoDestroyDialog.xhtml"/>
</h:form>
<h:outputScript library="js" name="common/forwardNotLoggedIn.js" rendered="#{!loginController.loggedIn}"/>
<h:outputScript library="js" name="common/forwardHome.js" rendered="#{!userInfoController.entitySelected}"/>
</ui:define>
</ui:composition>
</ui:composition>
TOP = ../..
SUBDIRS = DmWebPortal
include $(TOP)/tools/make/RULES_DM
TOP=../../..
all install: dist
clean clean-all clean-install distclean: pyc-clean
.PHONY: pyc-clean
pyc-clean:
rm -f `find . -name '*.pyc'`
# For compiling from command line, we have to use generic build properties file
.PHONY: dist
dist:
__version__ = "1.0 (2017.01.26)"
#!/usr/bin/env python
import os
from dm.common.exceptions.configurationError import ConfigurationError
from dm.common.api.dmApi import DmApi
from dm.aps_bss.impl.bssClient import BssClient
class ApsBssApi(DmApi):
''' Data Management API for APS Beamline Scheduling System. '''
def __init__(self, beamlineName=None, username=None, password=None, loginFile=None):
'''
Constructor.
:param beamlineName: beamline name (if not provided, environment variable DM_BEAMLINE_NAME must be set)
:type beamlineName: str
:param username: BSS username (if not provided, loginFile must be specified, or environment variable DM_BSS_LOGIN_FILE must be set)
:type username: str
:param password: BSS password (if not provided, loginFile must be specified, environment variable DM_BSS_LOGIN_FILE must be set)
:type password: str
:param loginFile: BSS login file (not used if username/password are provided; it can be replaced by environment variable DM_BSS_LOGIN_FILE)
:type loginFile: str
:raises ConfigurationError: in case beamline name or username/password are not provided, and corresponding environment variables are not set
Note that environment variable DM_BSS_LOGIN_FILE should contain
path to a file containing BSS username and password as a single line in
the '<username>|<password>' form.
>>> api = ApsBssApi(beamlineName='1-ID-B,C,E', username='dm', password='XYZ')
'''
DmApi.__init__(self)
if not username or not password:
if not loginFile:
loginFile = os.environ.get('DM_BSS_LOGIN_FILE')
if loginFile:
try:
# Assume form <username>|<password>
tokenList = open(loginFile).readline().split('|')
if len(tokenList) == 2:
username = tokenList[0].strip()
password = tokenList[1].strip()
except Exception, ex:
raise ConfigurationError('Could not determine username/password from BSS login file: %s' % str(ex))
if not username or not password:
raise ConfigurationError('Username and/or password were not provided, and DM_BSS_LOGIN_FILE is not set.')
if not beamlineName:
beamlineName = os.environ.get('DM_BEAMLINE_NAME')
if not beamlineName:
raise ConfigurationError('Beamline name was not provided, and DM_BEAMLINE_NAME is not set.')
self.beamlineName = beamlineName
self.bssClient = BssClient(username, password)
@DmApi.execute2
def listRuns(self):
'''
List all available runs.
:returns: list of RunInfo objects
:raises DmException: for any error
>>> runs = api.listRuns()
>>> for run in runs:
>>> print run['name']
'''
return self.bssClient.listRuns()
@DmApi.execute2
def getCurrentRun(self):
'''
Find current run.
:returns: RunInfo object
:raises DmException: for any error
>>> run = api.getCurrentRun()
'''
return self.bssClient.getCurrentRun()
@DmApi.execute2
def listBeamlineProposals(self, runName=None):
'''
List beamline proposals for a given run.
:param runName: run name (if not provided, current run name will be used)
:type runName: str
:returns: list of ProposalInfo objects
:raises DmException: for any error
>>> proposals = api.listBeamlineProposals()
>>> for proposal in proposals:
>>> print proposal['title']
'''
if not runName:
runName = self.getCurrentRun()['name']
return self.bssClient.listBeamlineProposals(self.beamlineName, runName)
@DmApi.execute2
def getBeamlineProposal(self, proposalId, runName=None):
'''
Get beamline proposal with a given id.
:param proposalId: proposal id
:type proposalId: str
:param runName: run name (if not provided, current run name will be used)
:type runName: str
:returns: ProposalInfo object
:raises ObjectNotFound: if proposal with the given id does not exist
:raises DmException: for any other error
>>> proposal = api.getBeamlineProposal(42096)
>>> for experimenter in proposal['experimenters']:
>>> print experimenter['badge'], experimenter['lastName']
'''
if not runName:
runName = self.getCurrentRun()['name']
return self.bssClient.getBeamlineProposal(proposalId, self.beamlineName, runName)
#######################################################################
# Testing.
if __name__ == '__main__':
api = ApsBssApi('1-ID-B,C,E')
print 'RUNS', api.listRuns()
print 'CURRRENT RUN: ', api.getCurrentRun()
print 'PROPOSALS: ', api.listBeamlineProposals()
print
print 'FIND PROPOSAL: ', api.getBeamlineProposal(42096)
print 'FIND PROPOSAL: ', api.getBeamlineProposal(52096)
#!/usr/bin/env python
from dm.common.exceptions.invalidRequest import InvalidRequest
from dm.common.cli.dmCli import DmCli
from dm.aps_bss.api.apsBssApi import ApsBssApi
class GetProposalCli(DmCli):
def __init__(self):
DmCli.__init__(self)
self.addOption('', '--id', dest='proposalId', help='Proposal id.')
self.addOption('', '--run', dest='runName', help='Run name. If not provided, current run will be used.')
self.addOption('', '--login-file', dest='loginFile', help='BSS login file. Login file may also be specified via environment variable DM_BSS_LOGIN_FILE.')
def checkArgs(self):
if not self.options.proposalId:
raise InvalidRequest('Missing proposal id.')
def runCommand(self):
self.parseArgs(usage="""
dm-get-proposal --id=PROPOSALID
[--run=RUNNAME]
[--login-file=LOGINFILE]
Description:
Retrieves beamline proposal for the given id.
""")
self.checkArgs()
proposalId = int(self.options.proposalId)
api = ApsBssApi(loginFile=self.options.loginFile)
proposal = api.getBeamlineProposal(proposalId=proposalId, runName=self.options.runName)
print proposal.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
#######################################################################
# Run command.
if __name__ == '__main__':
cli = GetProposalCli()
cli.run()
#!/usr/bin/env python
from dm.common.cli.dmCli import DmCli
from dm.aps_bss.api.apsBssApi import ApsBssApi
class ListProposalsCli(DmCli):
def __init__(self):
DmCli.__init__(self)
self.addOption('', '--run', dest='runName', help='Run name. If not provided, current run will be used.')
self.addOption('', '--login-file', dest='loginFile', help='BSS login file. It may be provided via environment variable DM_BSS_LOGIN_FILE.')
def checkArgs(self):
pass
def runCommand(self):
self.parseArgs(usage="""
dm-list-proposals
[--run=RUNNAME]
[--login-file=LOGINFILE]
Description:
Retrieves list of beamline proposals for the given run.
""")
self.checkArgs()
api = ApsBssApi(loginFile=self.options.loginFile)
proposals = api.listBeamlineProposals(runName=self.options.runName)
for proposal in proposals:
print proposal.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
#######################################################################
# Run command.
if __name__ == '__main__':
cli = ListProposalsCli()
cli.run()
#!/usr/bin/env python
from dm.common.cli.dmCli import DmCli
from dm.aps_bss.api.apsBssApi import ApsBssApi
class ListRunsCli(DmCli):
def __init__(self):
DmCli.__init__(self)
self.addOption('', '--login-file', dest='loginFile', help='BSS login file. It may be provided via environment variable DM_BSS_LOGIN_FILE.')
def checkArgs(self):
pass
def runCommand(self):
self.parseArgs(usage="""
dm-list-runs [--login-file=LOGINFILE]
Description:
Retrieves list of available runs.
""")
self.checkArgs()
api = ApsBssApi(loginFile=self.options.loginFile)
runs = api.listRuns()
for run in runs:
print run.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
#######################################################################
# Run command.
if __name__ == '__main__':
cli = ListRunsCli()
cli.run()
#!/usr/bin/env python
import datetime
from suds.wsse import Security
from suds.wsse import UsernameToken
from suds.client import Client
from dm.common.exceptions.objectNotFound import ObjectNotFound
from dm.common.objects.runInfo import RunInfo
from dm.common.objects.beamlineInfo import BeamlineInfo
from dm.common.objects.proposalInfo import ProposalInfo
from dm.common.objects.apsUserInfo import ApsUserInfo
from dm.common.exceptions.dmException import DmException
from dm.common.utility.loggingManager import LoggingManager
class BssClient:
WSDL_URL = 'https://schedule.aps.anl.gov/beamschedds/springws'
CACHE_DURATION_IN_SECONDS = 10
def __init__(self, username, password):
self.logger = LoggingManager.getInstance().getLogger(self.__class__.__name__)
self.__configure(username, password)
def __configure(self, username, password):
beamlineScheduleServiceUrl = self.WSDL_URL + '/beamlineScheduleService/beamlineScheduleWebService.wsdl'
runScheduleServiceUrl = self.WSDL_URL + '/runScheduleService/runScheduleWebService.wsdl'
try:
self.runScheduleServiceClient = Client(runScheduleServiceUrl)
self.runScheduleServiceClient.options.cache.setduration(seconds=self.CACHE_DURATION_IN_SECONDS)
self.setSoapHeader(self.runScheduleServiceClient, username, password)
self.beamlineScheduleServiceClient = Client(beamlineScheduleServiceUrl)
self.beamlineScheduleServiceClient.options.cache.setduration(seconds=self.CACHE_DURATION_IN_SECONDS)
self.setSoapHeader(self.beamlineScheduleServiceClient, username, password)
except Exception, ex:
self.logger.error('Cannot open BSS connection: %s' % str(ex))
raise DmException(exception=ex)
@classmethod
def setSoapHeader(cls, client, username, password):
security = Security()
token = UsernameToken(username, password)
token.setcreated()
security.tokens.append(token)
client.set_options(wsse=security)
def listRuns(self):
''' Return list of all runs. '''
result = self.runScheduleServiceClient.service.findAllRuns()
runArray = result.run
runs = []
for run in runArray:
runs.append(RunInfo({'name' : run.runName, 'startTime' : run.startTime, 'endTime' : run.endTime}))
return runs
def listRunsBetweenDates(self, startDate, endDate):
''' Find list of runs between given startDate and endDate. '''
result = self.runScheduleServiceClient.service.findAllRuns()
runArray = result.run
runs = []
for run in runArray:
if run.startTime >= startDate and run.endTime <= endDate:
runs.append(RunInfo({'name' : run.runName, 'startTime' : run.startTime, 'endTime' : run.endTime}))
return runs
def getRunForDates(self, startDate, endDate):
''' Find run that spans given startDate and endDate. '''
result = self.runScheduleServiceClient.service.findAllRuns()
runArray = result.run
for run in runArray:
if startDate >= run.startTime and endDate <= run.endTime:
return RunInfo({'name' : run.runName, 'startTime' : run.startTime, 'endTime' : run.endTime})
raise ObjectNotFound('No run found.')
def getCurrentRun(self):
''' Find current run. '''
now = datetime.datetime.now()
return self.getRunForDates(now, now)
def listBeamlines(self):
''' Find list of all beamlines. '''
result = self.beamlineScheduleServiceClient.service.findAllBeamlines()
beamlineArray = result.beamline
beamlines = []
for beamline in beamlineArray:
beamlines.append(BeamlineInfo({'name' : beamline.beamlineName, 'id' : beamline.id}))
return beamlines
def createProposalInfo(self, proposal):
experimenterArray = proposal.experimenters.experimenter
experimenters = []
for experimenter in experimenterArray:
user = ApsUserInfo({
'id' : experimenter.id,
'badge' : experimenter.badge,
'email' : experimenter.email,
'firstName' : experimenter.firstName,
'instId' : experimenter.instId,
'institution' : experimenter.institution,
'lastName' : experimenter.lastName
})
if hasattr(experimenter, 'piFlag'):
user['piFlag'] = experimenter.piFlag
experimenters.append(user)
proposalInfo = ProposalInfo({
'title' : proposal.proposalTitle,
'id' : proposal.id,
'experimenters' : experimenters
})
return proposalInfo
def listBeamlineProposals(self, beamlineName, runName):
''' Find beamline schedule for a given beamlineName and runName. '''
schedule = self.beamlineScheduleServiceClient.service.findBeamlineSchedule(beamlineName, runName)
activitiesArray = schedule.activities.activity
proposals = []
for activity in activitiesArray:
if hasattr(activity, 'beamtimeRequest'):
proposal = activity.beamtimeRequest.proposal
proposals.append(self.createProposalInfo(proposal))
return proposals
def getBeamlineProposal(self, proposalId, beamlineName, runName):
''' Find proposal with a given id, beamlineName and runName. '''
schedule = self.beamlineScheduleServiceClient.service.findBeamlineSchedule(beamlineName, runName)
activitiesArray = schedule.activities.activity
proposals = []
for activity in activitiesArray:
if hasattr(activity, 'beamtimeRequest'):
proposal = activity.beamtimeRequest.proposal
if proposal.id == proposalId:
return self.createProposalInfo(proposal)
raise ObjectNotFound('Proposal with id %s does not exist (beamline: %s; run: %s).' % (proposalId, beamlineName, runName))
if __name__ == '__main__':
bss = BssClient('DMADMIN', 'A2Fxew@11:76am')
now = datetime.datetime.now()
days = datetime.timedelta(days=180)
before = now - days
print before, now
runNames = bss.getRunsBetweenDates(before, now)
print 'RUNS: ', runNames
print 'CURRENT RUN: ', bss.getCurrentRun()
print bss.listBeamlines()
print bss.listBeamlineProposals('1-ID-B,C,E', '2017-1')
print
print bss.getBeamlineProposal(51190, '1-ID-B,C,E', '2017-1')
print
print bss.getBeamlineProposal(48258, '1-ID-B,C,E', '2017-1')