示例#1
0
    def __init__(self, companyId=0, logger=""):

        self.allSites= {}
        self.companyId = companyId
        self.logger = logger

        self.logger.info("SETUP USERS \n")

        api = jsonws.API()
        r = api.call("/group/get-groups", {'companyId': self.companyId, 'parentGroupId': '0', 'site':'true'})
        #print(r.url)
        #print (r.text)
        groups = json.loads(r.text)
        for g in groups:
            if 'Guest'  in g['groupKey']:
                self.groupID = g['groupId']

        #print("GROUP ID = ", self.groupID )

        r = api.call("/layout/get-layouts", {'groupId': self.groupID, 'privateLayout': 'false'})
        self.logger.info("/layout/get-layouts")
        self.logger.info(r.text)
        #print (r.text)
        sites = json.loads(r.text)

        #print("SITES AVAILABLE")
        for si in sites:
            self.allSites[si['friendlyURL']] = si['layoutId']
            if si['friendlyURL'] == "/home":
                self.welcometypeSettings = si['typeSettings']
                self.welcomeplid = si['plid']
        #print(self.allSites)

        self.journalService = journal.Journal(self.companyId, self.groupID, logger)
示例#2
0
    def initRoles(self):
        api = jsonws.API()
        roleNames = self.allRoles.keys()

        pprint(self.allRoles)

        dir = os.path.dirname(os.path.realpath(__file__))
        rolesfile = dir + '/config/roles.json'

        # Load Role configurations
        with open(rolesfile) as data_file:
            data = json.load(data_file)
        #pprint(data)

        # Create all roles that are not existing
        for role in data:
            if role["name"] not in roleNames:
                print("CREATE " + role["name"] + " ROLE")
                title = {'en_US': role["name"]}
                desc = {'en_US': role["description"]}

                param = {'className': 'com.liferay.portal.kernel.model.Role', 'classPk': '0', 'name': role["name"],
                         'titleMap': title, 'descriptionMap': desc, 'type': '1', 'subtype': None}

                r = api.call ("/role/add-role", param)
            

        r = api.call("/role/get-roles", {'companyId': self.companyId, 'types': '1'})
        self.allRoles = {}
        roles = json.loads(r.text)
        for rx in roles:
            self.allRoles [rx['name']] = rx['roleId']
示例#3
0
    def __init__(self, companyId=0, groupID=0, logger=""):
        self.allJournalArticles = {}
        self.companyId = companyId
        self.groupID = groupID
        self.logger = logger

        self.logger.info("SETUP Journal Articles \n")

        api = jsonws.API()
        r = api.call("/journal.journalarticle/get-articles", {
            'groupId': self.groupID,
            'folderId': '0'
        })
        print(r.text)
        articles = json.loads(r.text)
        for article in articles:
            print(article['urlTitle'])
            self.allJournalArticles[article['urlTitle']] = article[
                'articleId']  # "id": "32402" or "resourcePrimKey": "32403" or "articleId": "32401",

        dir = os.path.dirname(os.path.realpath(__file__))
        journalsfile = dir + '/config/journal.json'

        # Load Site configurations
        with open(journalsfile) as data_file:
            self.data = json.load(data_file)

        self.journalsNames = self.allJournalArticles.keys()
示例#4
0
    def setTheme(self):
        api = jsonws.API()
        param = {'groupId': self.groupID,
                 'privateLayout': 'false',
                 'themeId': "bibbox_WAR_bibboxtheme",
                 'colorSchemeId': "",
                 'css': ""}

        r = api.call("/layoutset/update-look-and-feel", param)
示例#5
0
    def __init__(self, companyId=0):
        self.allRoles = {}
        self.companyId = companyId
        api = jsonws.API()
        r = api.call("/role/get-roles", {'companyId': self.companyId, 'types': '1'})
#        print (r.text)
        roles = json.loads(r.text)
        for rx in roles:
            self.allRoles[rx['name']] = rx['roleId']
        print (self.allRoles)
示例#6
0
    def removePermission(self, plid, roleId, actionId):
        api = jsonws.API()
        param = {
            'companyId': self.companyId,
            'primKey': plid,
            'groupId': self.groupID,
            'name': 'com.liferay.portal.kernel.model.Layout',
            'roleId': roleId,
            'actionId': actionId,
            'scope': 4}

        r = api.call("/resourcepermission/remove-resource-permission", param)
        self.logger.info("/resourcepermission/remove-resource-permission")
        self.logger.info(r.text)
示例#7
0
    def setPermission(self, plid, roleId, actionId):
        api = jsonws.API()
        param = {
            'companyId': self.companyId,
            'primKey': plid,
            'groupId': self.groupID,
            'name': 'com.liferay.portal.kernel.model.Layout',
            'roleId': roleId,
            'actionIds': actionId
        }

        r = api.call("/resourcepermission/set-individual-resource-permissions", param)
        self.logger.info("/resourcepermission/set-individual-resource-permissions")
        self.logger.info(r.text)
示例#8
0
    def __init__(self, companyId=0):

        print("WELCOME IN USER SERVICE")
        self.allUsers = {}
        self.companyId = companyId
        self.defaultPassword = "******"

        api = jsonws.API()
        r = api.call("/user/get-company-users", {
            'companyId': self.companyId,
            'start': "0",
            'end': '1000'
        })
        users = json.loads(r.text)
        for ux in users:
            self.allUsers[ux['screenName']] = ux['userId']
        print(self.allUsers)
示例#9
0
    def updateWelcomePage(self, layoutID, site):
        api = jsonws.API()
        print("Update Welcome Site.")
        # Update Layout setings, place Portlet
        param = {'groupId': self.groupID,
                 'privateLayout': 'false',
                 'layoutId': layoutID,
                 'typeSettings': site["typeSettings"]}

        r = api.call("/layout/update-layout", param)
        self.logger.info("/layout/update-layout")
        self.logger.info(r.text)

        # CreateWebContent and update portletPreferences
        portletPreferences = self.journalService.createJournalArticle(site["articlename"])

        print("-------------")
        print("portletPreferences")
        print(portletPreferences)
        print("-------------")

        # Configure Portlet
        param = {
            'companyId': self.companyId,
            'plid': self.welcomeplid,
            'portletId': site["portletId"],
            'preferences': portletPreferences}
        print("self.companyId:" + self.companyId + " plid:" + self.welcomeplid + " portletId:" + site[
            "portletId"] + " preferences:" + portletPreferences)
        r = api.call("/BIBBOXDocker-portlet.set-portlet-configuration", param)

        self.logger.info("/BIBBOXDocker-portlet.set-portlet-configuration")
        self.logger.info(r.text)

        # Setup Permissions
        roleService = roles.Roles(companyId=self.companyId)
        roleService.initRoles()
        roleIds = roleService.rolesIds()

        self.removePermission(self.welcomeplid, roleIds['Guest'], "VIEW")
        for permission in site['permission']:
            for userrole in permission:
                self.setPermission(self.welcomeplid, roleIds[userrole], permission[userrole])
        print("Update Welcome Site. ...done")
示例#10
0
 def description(self, roleId):
     api = jsonws.API()
     return api.call("/role/get-role", {'roleId': roleId})
示例#11
0
    def createSite(self, sitejson):
        api = jsonws.API()

        roleService = roles.Roles(companyId=self.companyId)
        roleService.initRoles()
        roleIds = roleService.rolesIds()

        print("CREATE " + sitejson["name"] + " SITE")

        parentLayoutId = 0
        if(sitejson["parentSite"] != "0"):
            parentLayoutId = self.allSites[sitejson["parentSite"]]

        # Create Layout
        param = {'groupId' : self.groupID,
                'privateLayout' : 'false',
                'parentLayoutId': parentLayoutId,
                'name' : sitejson["name"],
                'title': sitejson["title"],
                'description': sitejson["description"],
                'type': 'portlet',
                'hidden' : sitejson["hidden"],
                'friendlyURL' : sitejson["friendlyURL"] }

        r = api.call ("/layout/add-layout", param)
        self.logger.info("/layout/add-layout")
        self.logger.info(r.text)

        site = json.loads(r.text)
        layoutID = site['layoutId']
        plid = site['plid']
        self.allSites[sitejson["friendlyURL"]] = layoutID

        # Update Layout setings, place Portlet
        param = {'groupId': self.groupID,
                 'privateLayout': 'false',
                 'layoutId': layoutID,
                 'typeSettings': sitejson["typeSettings"]}

        r = api.call("/layout/update-layout", param)
        self.logger.info("/layout/update-layout")
        self.logger.info(r.text)

        # Setup Permissions
        self.removePermission(plid, roleIds['Guest'], "VIEW")
        for permission in sitejson['permission']:
            for userrole in permission:
                self.setPermission(plid, roleIds[userrole], permission[userrole])

        if sitejson["portlettype"] == "none":
            return

        if sitejson["portlettype"] == "JournalArticle":
            # CreateWebContent and update portletPreferences
            sitejson["portletPreferences"] = self.journalService.createJournalArticle(sitejson["articlename"])

        # Configure Portlet
        param = {
                'companyId': self.companyId,
                'plid': plid,
                'portletId': sitejson["portletId"],
                'preferences': sitejson["portletPreferences"]}
        print("self.companyId:" + self.companyId + " plid:" + plid + " portletId:" + sitejson["portletId"] + " preferences:" + sitejson["portletPreferences"])
        r = api.call("/BIBBOXDocker-portlet.set-portlet-configuration", param)

        self.logger.info("/BIBBOXDocker-portlet.set-portlet-configuration")
        self.logger.info(r.text)
示例#12
0
    def createJournalArticlePrivate(self, journalarticle):
        cdate = datetime.now()

        print(cdate)

        api = jsonws.API()
        print("Create " + journalarticle["articleURL"])
        r = api.call(
            "/journal.journalarticle/add-article", {
                'groupId': self.groupID,
                'folderId': '0',
                'classNameId': '0',
                'classPK': '0',
                'articleId': '',
                'autoArticleId': 'true',
                'titleMap': journalarticle["titleMap"],
                'descriptionMap': '{}',
                'content': journalarticle["content"],
                'ddmStructureKey': 'BASIC-WEB-CONTENT',
                'ddmTemplateKey': 'BASIC-WEB-CONTENT',
                'layoutUuid': '',
                'displayDateMonth': cdate.month - 1,
                'displayDateDay': cdate.day,
                'displayDateYear': cdate.year - 1,
                'displayDateHour': cdate.hour,
                'displayDateMinute': cdate.minute,
                'expirationDateMonth': '0',
                'expirationDateDay': '0',
                'expirationDateYear': '0',
                'expirationDateHour': '0',
                'expirationDateMinute': '0',
                'neverExpire': 'true',
                'reviewDateMonth': '0',
                'reviewDateDay': '0',
                'reviewDateYear': '0',
                'reviewDateHour': '0',
                'reviewDateMinute': '0',
                'neverReview': 'true',
                'indexable': 'true',
                'articleURL': journalarticle["articleURL"]
            })
        print(r.text)
        article = json.loads(r.text)

        r2 = api.call("/assetentry/get-company-entries", {
            'companyId': self.companyId,
            'start': '-1',
            'end': '-1'
        })

        assets = json.loads(r2.text)
        print(r2.text)
        uuid = ""
        for asset in assets:
            if asset['classPK'] == article['resourcePrimKey']:
                print("Asset found for article")
                print("UUID: " + asset['classUuid'])
                uuid = asset['classUuid']

        template = "<portlet-preferences><preference><name>enableComments</name><value>false</value></preference><preference><name>enableRelatedAssets</name><value>true</value></preference><preference><name>subtypeFieldsFilterEnabled</name><value>false</value></preference><preference><name>enableViewCountIncrement</name><value>true</value></preference><preference><name>delta</name><value>20</value></preference><preference><name>showExtraInfo</name><value>true</value></preference><preference><name>showAvailableLocales</name><value>false</value></preference><preference><name>displayStyleGroupId</name><value>20147</value></preference><preference><name>assetLinkBehavior</name><value>showFullContent</value></preference><preference><name>selectionStyle</name><value>manual</value></preference><preference><name>displayStyle</name><value>full-content</value></preference><preference><name>enableSocialBookmarks</name><value>true</value></preference><preference><name>enablePermissions</name><value>true</value></preference><preference><name>enableRss</name><value>false</value></preference><preference><name>socialBookmarksDisplayStyle</name><value>menu</value></preference><preference><name>classNameIds</name></preference><preference><name>emailAssetEntryAddedEnabled</name><value>false</value></preference><preference><name>enableTagBasedNavigation</name><value>false</value></preference><preference><name>metadataFields</name><value></value></preference><preference><name>showContextLink</name><value>true</value></preference><preference><name>showQueryLogic</name><value>false</value></preference><preference><name>enableCommentRatings</name><value>false</value></preference><preference><name>emailFromAddress</name><value>[email protected]</value></preference><preference><name>enableRatings</name><value>false</value></preference><preference><name>enablePrint</name><value>false</value></preference><preference><name>assetEntryXml</name><value>&lt;?xml version=&#34;§§version&#34;?&gt;[$NEW_LINE$][$NEW_LINE$]&lt;asset-entry&gt;[$NEW_LINE$]	&lt;asset-entry-type&gt;com.liferay.journal.model.JournalArticle&lt;/asset-entry-type&gt;[$NEW_LINE$]	&lt;asset-entry-uuid&gt;§§uuid&lt;/asset-entry-uuid&gt;[$NEW_LINE$]&lt;/asset-entry&gt;</value></preference><preference><name>socialBookmarksDisplayPosition</name><value>bottom</value></preference><preference><name>showAssetTitle</name><value>true</value></preference><preference><name>extensions</name></preference><preference><name>emailFromName</name><value>BIBBOX</value></preference><preference><name>paginationType</name><value>none</value></preference><preference><name>abstractLength</name><value>200</value></preference><preference><name>showMetadataDescriptions</name><value>true</value></preference><preference><name>enableFlags</name><value>false</value></preference><preference><name>showAddContentButton</name><value>true</value></preference></portlet-preferences>"
        template = template.replace("§§version", str(article["version"]))
        template = template.replace("§§uuid", str(uuid))

        return template
示例#13
0
def writeSetupDoneConfig():
    target = open("/etc/bibbox/conf.d/setup.cfg", 'w')
    target.write('setup="done"')
    target.close()

setupLogger()

sys.stdout.write("Check Vagrant Setup Error. \n")
logger.info("Check Vagrant Setup Error. \n")
setupchecker.Setupchecker(logger)

sys.stdout.write("Trying to connect to liferay server. \n")
logger.info("Trying to connect to liferay server. \n")
testServerStarted(0)

sys.stdout.write("SETUP SITES \n")
logger.info("SETUP SITES \n")
siteService = sites.Sites('20116', logger)
siteService.initSites()

sys.stdout.write("SETUP USERS \n")
logger.info("SETUP USERS \n")
userService = users.Users (companyId = '20116')
userService.initUsers()

api = jsonws.API()

writeSetupDoneConfig()

示例#14
0
    def initUsers(self):

        api = jsonws.API()

        print("FIRST GENERATE THE ROLES")

        roleService = roles.Roles(companyId=self.companyId)
        roleService.initRoles()
        roleIds = roleService.rolesIds()

        screenNames = self.allUsers.keys()

        dir = os.path.dirname(os.path.realpath(__file__))
        usersfile = dir + '/config/users.json'

        # Load User configurations
        with open(usersfile) as data_file:
            data = json.load(data_file)
        #pprint(data)

        # Create all users that are not existing
        for user in data:
            if user["screenName"] not in screenNames:
                print("CREATE " + user["jobTitle"])

                rIDs = []

                for rID in user["roleIds"]:
                    rIDs.append(roleIds[rID])

                param = {
                    "companyId": self.companyId,
                    "autoPassword": False,
                    "password1": self.defaultPassword,
                    "password2": self.defaultPassword,
                    "autoScreenName": False,
                    "screenName": user["screenName"],
                    "emailAddress": user["emailAddress"],
                    "facebookId": 0,
                    "openId": "",
                    "locale": "en_US",
                    "firstName": user["firstName"],
                    "middleName": user["middleName"],
                    "lastName": user["lastName"],
                    "prefixId": 0,
                    "suffixId": 0,
                    "male": user["male"],
                    "birthdayMonth": user["birthdayMonth"],
                    "birthdayDay": user["birthdayDay"],
                    "birthdayYear": user["birthdayYear"],
                    "jobTitle": user["jobTitle"],
                    "groupIds": None,
                    "organizationIds": None,
                    "roleIds": rIDs,
                    "userGroupIds": None,
                    "sendEmail": False,
                    "serviceContext": user["serviceContext"]
                }
                r = api.call("/user/add-user", param)
                tmp_user = json.loads(r.text)

                pic = dir + user["avatar"]

                with open(pic, 'rb') as f:
                    picdata = f.read()

                param = {
                    "userId": tmp_user['userId'],
                    "bytes": list(picdata),
                }
                r = api.call("/user/update-portrait", param)
示例#15
0
 def description(self, screenName):
     api = jsonws.API()
     return api.call("/user/get-user-by-screen-name", {
         'companyId': self.companyId,
         'screenName': screenName
     })