106 lines
3.3 KiB
Python
106 lines
3.3 KiB
Python
|
import re
|
||
|
|
||
|
from datetime import datetime
|
||
|
from h1wsutils import H1WebServiceUtils
|
||
|
|
||
|
# Some configuration Data statically added (for examples only!)
|
||
|
USER = "mo_webservice_user"
|
||
|
PASSWD = "geheim"
|
||
|
HOST = "hisinone-7350-s"
|
||
|
WSDL_FOLDER = "wsdl"
|
||
|
|
||
|
|
||
|
SERVICES = (
|
||
|
"StayAbroadService",
|
||
|
"PersonService",
|
||
|
"PersonAddressService",
|
||
|
"StudentService201812",
|
||
|
"StudentService",
|
||
|
"KeyvalueService"
|
||
|
)
|
||
|
|
||
|
|
||
|
h1util = H1WebServiceUtils(USER, PASSWD, HOST, WSDL_FOLDER, SERVICES)
|
||
|
h1util.download_wsdls()
|
||
|
|
||
|
# Preparing proxies
|
||
|
abroad_svc = h1util.get_proxy("StayAbroadService")
|
||
|
person_svc = h1util.get_proxy("PersonService")
|
||
|
person_address_svc = h1util.get_proxy("PersonAddressService")
|
||
|
student2_svc = h1util.get_proxy("StudentService201812")
|
||
|
student_svc = h1util.get_proxy("StudentService")
|
||
|
value_svc = h1util.get_proxy("KeyvalueService")
|
||
|
|
||
|
# Input data for example, has to be replaced with values from real system
|
||
|
# in move on environment
|
||
|
#USERNAME_FROM_SHIBBOLETH = "albrecht4@beispielhochschule.de"
|
||
|
#FOREIGN_COUNTRY_ISO = "AU" # iso3166_1_alpha_2
|
||
|
|
||
|
# Alternative ones for testing
|
||
|
USERNAME_FROM_SHIBBOLETH = "bauer2@beispielhochschule.de"
|
||
|
FOREIGN_COUNTRY_ISO = "DK" # iso3166_1_alpha_2
|
||
|
|
||
|
# Some simple sample for validating and handling the fully qualified username from Shibboleth
|
||
|
UNIVERSITY_SUFFIX_SHIBBOLETH_REGEX = "^(?P<username>[a-zA-Z0-9]+)@beispielhochschule.de$"
|
||
|
|
||
|
matches = re.match(UNIVERSITY_SUFFIX_SHIBBOLETH_REGEX, USERNAME_FROM_SHIBBOLETH)
|
||
|
if not matches:
|
||
|
print("Invalid User, not allowed to be used in this context")
|
||
|
exit(code=1)
|
||
|
|
||
|
username = matches["username"]
|
||
|
|
||
|
# Finding person by username
|
||
|
person_ids = person_svc.service.findPerson(
|
||
|
username=username,
|
||
|
studyTermYear=datetime.now().year # To focus the problem that usernames can be reused for new persons after some time of inactivity
|
||
|
)
|
||
|
if len(person_ids) != 1:
|
||
|
print(f"ERROR: user assignment invalid or not existent, please check it in HISinOne ({len(person_ids)})")
|
||
|
exit(code=2)
|
||
|
|
||
|
person_id = person_ids[0]
|
||
|
|
||
|
# Fetching information about the user
|
||
|
student_info = student2_svc.service.readStudentByPersonId(
|
||
|
person_id,
|
||
|
withDegreePrograms=True,
|
||
|
withAddresses=True
|
||
|
)
|
||
|
print(student_info)
|
||
|
|
||
|
|
||
|
#
|
||
|
#
|
||
|
# Then continue to work in MoveOn
|
||
|
#
|
||
|
#
|
||
|
|
||
|
# After student is back from exchange semester, write back statistics data to HISinOne
|
||
|
|
||
|
# Those calls you can use to see what values are available within HISinOne
|
||
|
#STAY_ABROAD_TYPES = value_svc.service.getAll(valueClass="StayAbroadTypeValue", lang="de")
|
||
|
#print(STAY_ABROAD_TYPES)
|
||
|
|
||
|
#MOBILITY_PROGRAMS = value_svc.service.getAll(valueClass="MobilityProgramValue", lang="de")
|
||
|
#print(MOBILITY_PROGRAMS)
|
||
|
|
||
|
# In our sample case, the person did studies on a foreign university
|
||
|
STAY_ABROAD_TYPE = "01"
|
||
|
RESEARCH_FACILITY_TYPE="UNI"
|
||
|
# and he did this via ERASMUS which means an EU-Program
|
||
|
MOBILITY_PROGRAM = "01"
|
||
|
|
||
|
# Note:
|
||
|
# calling webservice user needs the right cs.psv.stayabroad.EDIT_STAYABROAD within hisinone!
|
||
|
result = abroad_svc.service.createStayAbroad(
|
||
|
personId=person_id,
|
||
|
country=FOREIGN_COUNTRY_ISO, # iso3166_1_alpha_2 of the country the student has been to
|
||
|
numberOfMonth=7,
|
||
|
startdate="2022-01-15",
|
||
|
enddate="2022-07-15",
|
||
|
stayAbroadTypeValue=STAY_ABROAD_TYPE,
|
||
|
mobilityProgramValue=MOBILITY_PROGRAM,
|
||
|
researchFacilityName="Sampleuniversity of Denmark",
|
||
|
researchFacilityTypeValue=RESEARCH_FACILITY_TYPE
|
||
|
)
|